• 省市县三级联动(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);
    
        }
    }
  • 相关阅读:
    centos7下安装jdk
    在centos7关于防火墙的基本操作
    hadoop的特性
    java中怎么使用combobox,并获取其选中的值
    @suppressWarnings("unchecked")在java中的作用
    The processing instruction target matching "[xX][mM][lL]" is not allowed.
    Invalid byte 2 of 2-byte UTF-8 sequence解决方案
    Nmap
    XSS-笔记
    sql盲注-笔记
  • 原文地址:https://www.cnblogs.com/liuyudong0825/p/4953076.html
Copyright © 2020-2023  润新知