首页 > 代码库 > ASP.NET Web Form服务器控件三级联动
ASP.NET Web Form服务器控件三级联动
<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; } }
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; }
ASP.NET Web Form服务器控件三级联动
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。