2015-03-03 50 views
0

我有ASP網頁連接GridView1連接到SqlDataSource1DropDownList1這對SqlDataSource1 SQL腳本產生影響。在GridView上刷新數據DropDownList選擇索引變化

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="terminalLog.aspx.cs" Inherits="_2013web.terminalLog" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> 
    <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2" DataTextField="Id" DataValueField="Id" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True" Height="95px" OnLoad="DropDownList1_Load" OnTextChanged="DropDownList1_TextChanged" Width="481px"> 
    </asp:DropDownList> 
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:logsConnectionString1 %>" SelectCommand="SELECT [ClientID], [Msg], [LogLevel], [Date] FROM [logs] WHERE ([ClientID] = @ClientID) ORDER BY [Date]"> 
     <SelectParameters> 
      <asp:ControlParameter ControlID="DropDownList1" DefaultValue="80" Name="ClientID" PropertyName="SelectedValue" Type="Int32" /> 
     </SelectParameters> 
    </asp:SqlDataSource> 
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Width="2104px"> 
     <Columns> 
      <asp:BoundField DataField="ClientID" HeaderText="ClientID" SortExpression="ClientID" /> 
      <asp:BoundField DataField="Msg" HeaderText="Msg" SortExpression="Msg" /> 
      <asp:BoundField DataField="LogLevel" HeaderText="LogLevel" SortExpression="LogLevel" /> 
      <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" /> 
     </Columns> 
    </asp:GridView> 
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:logsConnectionString1 %>" SelectCommand="SELECT [Id] FROM [clients] ORDER BY [Id]"></asp:SqlDataSource> 
</asp:Content> 

我需要在選擇DropDownList1新的價值,以顯示新的數據。

我想我需要的東西,在那裏寫:

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    SqlDataSource1.Update(); 
} 

SqlDataSource1.Update();沒有幫助。

DropDownList1_SelectedIndexChanged應該執行什麼?

+0

GridView1.DataBind()如果你想刷新網格。 – 2015-03-03 12:06:11

+0

'DropDownList1'連線到'SqlDatasource1'的控制參數和GridView屬性:' fnostro 2015-03-03 21:58:16

回答

1

沒有也沒有必要寫任何代碼,根據您的問題,您DropDownList1True當選定值改變你的GridView將自動更新AutoPostBack

0
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    GridView1.DataBind(); 
}