我正在使用3个下拉列表,从本地数据库获取数据。每个下拉列表都是从上面的下拉列表中选择的。有点像国家,地区,城镇设置(取决于你获得一组地区的国家,取决于地区来获得一组城镇)这是使用visual studio 2013中的sqldatasource正常工作。
当我更改以前的下拉列表值之一时出现问题,例如:我在dropdownlist1中选择了一个国家/地区,在dropdownlist 2中选择了一个地区,在dropdownlist3中选择了一个城镇。我想要做的是:当我将dropdownlist1的值更改为另一个国家/地区时,将其他2设置为空白。
编辑代码
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack ="True" DataSourceID="SqlDataSource1" DataTextField="area" DataValueField="area" Font-Bold="True" Width="250px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" >
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [area] FROM [Area]"></asp:SqlDataSource>
<br />
<br />
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2" DataTextField="categoria" DataValueField="categoria" Font-Bold="True" Width="250px" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged" Enabled="False">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM Categoria WHERE Categoria.area = @area">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="area" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<br />
<asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="SqlDataSource3" DataTextField="problema" DataValueField="problema" Font-Bold="True" Height="16px" Width="250px" OnSelectedIndexChanged="DropDownList3_SelectedIndexChanged" AutoPostBack="True" Enabled="False">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM PROBLEMA WHERE problema.categoria = @categoria;">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList2" Name="categoria" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>