zoukankan      html  css  js  c++  java
  • 省市县三级联动(webFrom...DropdownList)

    编辑页面

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
        </div>
            <asp:DropDownList ID="DropDownList1" runat="server" Width="100px" AutoPostBack="True" Height="50px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" style="margin-bottom: 0px" >
            </asp:DropDownList>
            <asp:DropDownList ID="DropDownList2" runat="server" Width="100px" AutoPostBack="True" Height="50px" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
            </asp:DropDownList>
            <asp:DropDownList ID="DropDownList3" runat="server" Width="100px" AutoPostBack="True" Height="50px">
            </asp:DropDownList>
        </form>
    </body>
    </html>

    编辑cs

    public partial class Test2 : System.Web.UI.Page
    {
        public DataClassesDataContext context;
    
        protected void Page_Load(object sender, EventArgs e)
        {
            context = new DataClassesDataContext();
            if(!IsPostBack)
            {
                databind("0001");
                datashibind("11");
                dataxianbind("1101");
            }
    
        }
        private void databind(string parentareacode)
        {
    
            var querydata = from q in context.ChinaStates
                        where q.ParentAreaCode == parentareacode
                        select q;
            DropDownList1.DataSource = querydata;//指定数据源
       
            //DropDownList1.Items.Insert(0,new ListItem("请选择单位"));
         
            DropDownList1.DataTextField = "AreaName";//界面上显示的是地名
            DropDownList1.DataValueField = "AreaCode";//存的是地区编号
       
            DropDownList1.DataBind();
    
    
        }
        private void datashibind(string parentareacode)
        {
            var querydata = from q in context.ChinaStates
                            where q.ParentAreaCode ==parentareacode
                            select q;
            DropDownList2.DataSource = querydata;
    
            DropDownList2.DataTextField = "AreaName";//界面上显示的是地名
            DropDownList2.DataValueField = "AreaCode";//存的是地区编号
            DropDownList2.DataBind();
    
        }
        private void dataxianbind(string parentareacode)
        {
    
            var querydata = context.ChinaStates.Where(r=>r.ParentAreaCode==parentareacode);
            DropDownList3.DataSource = querydata;
            DropDownList3.DataTextField = "AreaName";//界面上显示的是地名
            DropDownList3.DataValueField = "AreaCode";//存的是地区编号
            DropDownList3.DataBind();
    
        }
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string code = DropDownList1.SelectedValue.ToString();
            datashibind(code);
            if (DropDownList2.Items.Count > 0)
            {
                string s = DropDownList2.SelectedItem.Value.ToString();
                dataxianbind(s);
            }
            else 
            {
                DropDownList3.Items.Clear();
            }
           
       
          
    
        }
        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {
            string code = DropDownList2.SelectedValue.ToString();
            dataxianbind(code);
    
        }
    }
  • 相关阅读:
    003_当表中字段不能为空,但却没有赋值时?
    019_SSM——mybatis的#{id}可以根据是对象参数调用setId()的原码?
    002_com.wkcto自动添加错误
    018_SSM——Spring框架的byName与ByType实现自动注入的原码是什么呢?
    as3 文档类引用
    as3 连接mysql
    as2 针对加载进来的swf操作
    as3 arguments.callee与... (rest)
    as3 string split方法一些注意
    as3 Function 中的call与apply方法
  • 原文地址:https://www.cnblogs.com/liuyudong0825/p/4953076.html
Copyright © 2011-2022 走看看