我的网络表单中有两个DropDownList
s,当我在第一个下拉列表中选择一个值时,我希望在第二个下拉列表中自动选择一个相关值。
这是我目前拥有的:
<table>
<tr>
<td>
<asp:Label ID="lbmanu" runat="server" Text="Furniture Manufacturer :
"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddmanu" runat="server"
DataSourceID="Sql_fur_model_manu"
DataTextField="manufacturer" DataValueField="manufacturer"
onselectedindexchanged="ddmanu_SelectedIndexChanged">
</asp:DropDownList>
<asp:SqlDataSource ID="Sql_fur_model_manu" runat="server"
ConnectionString="<%$ ConnectionStrings:conStr %>"
SelectCommand="SELECT DISTINCT [manufacturer] FROM
[furniture_manufacturer]">
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbtype" runat="server" Text="Furniture Type :
"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddtype" runat="server" AutoPostBack="True">
</asp:DropDownList>
</td>
</tr>
</table>
代码背后:
protected void ddmanu_SelectedIndexChanged(object sender, EventArgs e)
{
string query = "select furniture from furniture_model where manufacturer='" +
ddmanu.SelectedValue.ToString() + "'";
con.Open();
cmd = new SqlCommand(query, con);
DataTable dt = Select(query);
cmd.ExecuteNonQuery();
ddtype.DataSource = dt;
ddtype.DataTextField = "manufacturer";
ddtype.DataValueField = "furniture";
ddtype.DataBind();
}