asp下拉框联动
<form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <div> <asp:Label runat="server" ID="lbl_Name"></asp:Label> <asp:TextBox runat="server" ID="txt_Name"></asp:TextBox> <asp:UpdatePanel runat="server"> <ContentTemplate> <asp:DropDownList runat="server" ID="ddlProvince" AutoPostBack="true" OnSelectedIndexChanged="Drop_Province_Change"> <asp:ListItem Text="--请选择--" Value="-1"></asp:ListItem> <asp:ListItem Text="浙江省" Value="0"></asp:ListItem> <asp:ListItem Text="江苏省" Value="1"></asp:ListItem> </asp:DropDownList> <asp:DropDownList runat="server" ID="ddlCity" AutoPostBack="true" OnSelectedIndexChanged="Drop_City_Change"> </asp:DropDownList> <asp:DropDownList runat="server" ID="ddlArea"> </asp:DropDownList> </ContentTemplate> </asp:UpdatePanel> <asp:Button runat="server" ID="btnSave" Text="保存" OnClick="btn_Save_Click" /> </div> </form>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
protected void Drop_Province_Change(object sender, EventArgs e) { if (ddlProvince.SelectedValue == "-1") { Industry_Init(ddlCity); } else if (ddlProvince.SelectedValue == "0") { ddlCity.Items.Clear(); ddlCity.Items.Add(new ListItem("--请选择--", "-1")); ddlCity.Items.Add(new ListItem("杭州", "0")); ddlCity.Items.Add(new ListItem("绍兴", "1")); } else if (ddlProvince.SelectedValue == "1") { ddlCity.Items.Clear(); ddlCity.Items.Add(new ListItem("--请选择--", "-1")); ddlCity.Items.Add(new ListItem("苏州", "3")); ddlCity.Items.Add(new ListItem("无锡", "4")); } Industry_Init(ddlArea); } protected void Drop_City_Change(object sender, EventArgs e) { if (ddlCity.SelectedValue == "-1") { Industry_Init(ddlArea); } else if (ddlCity.SelectedValue == "0") { ddlArea.Items.Clear(); ddlArea.Items.Add(new ListItem("--请选择--", "-1")); ddlArea.Items.Add(new ListItem("西湖区", "0")); ddlArea.Items.Add(new ListItem("下城区", "1")); } else if (ddlCity.SelectedValue == "0") { ddlArea.Items.Clear(); ddlArea.Items.Add(new ListItem("--请选择--", "-1")); ddlArea.Items.Add(new ListItem("西湖区", "0")); ddlArea.Items.Add(new ListItem("下城区", "1")); } else if (ddlCity.SelectedValue == "1") { ddlArea.Items.Clear(); ddlArea.Items.Add(new ListItem("--请选择--", "-1")); ddlArea.Items.Add(new ListItem("越城区", "0")); ddlArea.Items.Add(new ListItem("上虞", "1")); } else if (ddlCity.SelectedValue == "2") { ddlArea.Items.Clear(); ddlArea.Items.Add(new ListItem("--请选择--", "-1")); ddlArea.Items.Add(new ListItem("苏州1区", "0")); ddlArea.Items.Add(new ListItem("苏州2区", "1")); } else if (ddlCity.SelectedValue == "3") { ddlArea.Items.Clear(); ddlArea.Items.Add(new ListItem("--请选择--", "-1")); ddlArea.Items.Add(new ListItem("无锡1区", "0")); ddlArea.Items.Add(new ListItem("无锡2区", "1")); } } public void Industry_Init(DropDownList dropDown) { dropDown.Items.Clear(); dropDown.Items.Add("--请选择--"); } public void btn_Save_Click(object sender, EventArgs e) { var text = ddlProvince.SelectedItem.Text + ddlCity.SelectedItem.Text + ddlArea.SelectedItem.Text; ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "myscript", "alert('" + text + "'); ", true); }