<form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server" style="display:inline-block"> <ContentTemplate> <asp:DropDownList ID="ddltype1" runat="server" OnSelectedIndexChanged="ddltype1_SelectedIndexChanged" AutoPostBack="true"> </asp:DropDownList> <asp:DropDownList ID="ddltype2" runat="server" Visible="false" OnSelectedIndexChanged="ddltype2_SelectedIndexChanged" AutoPostBack="true"> </asp:DropDownList> <asp:DropDownList ID="ddltype3" runat="server" Visible="false"> </asp:DropDownList> </ContentTemplate> </asp:UpdatePanel>
三级联动页面代码
protected void ddltype1_SelectedIndexChanged(object sender, EventArgs e) { string ChannelID = ddltype1.SelectedValue; if (ChannelID == "") { ddltype2.Visible = false; return; } Binder(Convert.ToInt32(ChannelID), ddltype2); } protected void ddltype2_SelectedIndexChanged(object sender, EventArgs e) { string ChannelID = ddltype2.SelectedValue; if (ChannelID == "") { ddltype3.Visible = false; return; } Binder(Convert.ToInt32(ChannelID), ddltype3); } private void Binder(int ChannelID, DropDownList ddl) { if (ddl.Items.Count > 0) { ddl.Items.Clear(); } ddl.DataTextField = "User_Group_Name"; ddl.DataValueField = "User_Group_Id"; List<Community.Model.USER_GROUP> lnc = Community.BLL.BUSER_GROUPExtBLL.GetGROUP(ChannelID); if (lnc.Count > 0) { ddl.Visible = true; ddl.DataSource = lnc; ddl.DataBind(); ddl.Items.Insert(0, new ListItem("---请选择----", "")); } else { ddl.Visible = false; } }
三级联动后台SelectedIndexChanged事件
string type1 = ddltype1.SelectedValue; string type2 = ddltype2.SelectedValue; string type3 = ddltype3.SelectedValue; if (type1 != "" && type2 != "" && type3 != "") { channelid = Convert.ToInt32(type3); } else if (type1 != "" && type2 != "" && type3 == "") { channelid = Convert.ToInt32(type2); } else if (type1 != "" && type2 == "" && type3 == "") { channelid = Convert.ToInt32(type1); } else { channelid = 0; }
三级联动后台接受值的代码
时间: 2024-10-10 05:02:36