码迷,mamicode.com
首页 > Web开发 > 详细

ASP.NET Web Form服务器控件三级联动

时间:2017-06-16 14:22:50      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:orm   name   man   服务   update   rgs   src   ddl   end   

技术分享
<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>
                        &nbsp;
                        <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;
            }
三级联动后台接受值的代码

 

ASP.NET Web Form服务器控件三级联动

标签:orm   name   man   服务   update   rgs   src   ddl   end   

原文地址:http://www.cnblogs.com/sharing1986687846/p/7027026.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!