0
我正在創建一個將顯示來自SQL數據庫的特定數據的ASP.NET Web應用程序。我創建了3個DataSources每個特定的數據我想查看從DropDownList中選擇。綁定到GridView顯示的C#ASP.NET應用程序組合框問題
我的DropDownList編碼C#側是如下:在ASP.NET方
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string SourceName = DropDownList1.SelectedValue;
GridView1.DataSourceID = SourceName;
GridView1.DataBind();
}
DropDownList的編碼:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="DataSource_Gerneral">General Overview</asp:ListItem>
<asp:ListItem Value="DataSource_Portfolio">Portfolio</asp:ListItem>
<asp:ListItem Value="DataSource_ErrorLog">Error Log</asp:ListItem>
</asp:DropDownList>
網格視圖編碼在ASP.NET一邊是如下:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BorderStyle="Inset" CellPadding="4" DataKeyNames="Call_Sign" DataSourceID= "DataSource_Gerneral" Font-Size="Smaller" ForeColor="#333333" GridLines="None" Height="16px" Width="155px" AllowPaging="True" AllowSorting="True" ClientIDMode="AutoID" HorizontalAlign="Justify" PageSize="100" OnSelectedIndexChanged="GridView1_SelectedIndexChanged1">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="Call_Sign" HeaderText="Call_Sign" ReadOnly="True" SortExpression="Call_Sign" />
<asp:BoundField DataField="Current_Price" HeaderText="Current_Price" SortExpression="Current_Price" />
<asp:BoundField DataField="Stock_Market" HeaderText="Stock_Market" SortExpression="Stock_Market" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
我測試了下拉列表以確保它實際上正在更改DatasourceID。它工作正常。但是,當Selected視圖被選中到下拉列表中時,gridview保持不變。我一直在尋找一種顯示新數據的方式。我錯過了什麼!我希望它只是一個簡單的代碼行,它將在運行時改變gridview。