• ASP.NET实现省市区三级联动(局部刷新)


    跟前一篇ASP.NET实现年月日三级联动(局部刷新)一样,没什么技术含量,直接上代码

    <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:DropDownList ID="ddl_Province" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddl_Province_SelectedIndexChanged">
                </asp:DropDownList>
                <asp:DropDownList ID="ddl_City" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddl_City_SelectedIndexChanged">
                </asp:DropDownList>
                <asp:DropDownList ID="ddl_Area" runat="server">
                </asp:DropDownList>
            </ContentTemplate>
        </asp:UpdatePanel>
    protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    BindProvince();
                    BindCity(ddl_Province.SelectedItem.Value);
                    BindArea(ddl_City.SelectedItem.Value);
                }
            }
    
            #region 三级省市区联动xml
            private void BindProvince()
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(Server.MapPath("ChinaArea.xml"));
                XmlNodeList nodelist = xmlDoc.SelectNodes("area/province[@provinceID]");
                ListItem li = null;
                foreach (XmlNode myNode in nodelist)
                {
                    li = new ListItem();
                    li.Value = myNode.Attributes["provinceID"].Value;
                    li.Text = myNode.Attributes["province"].Value;
                    this.ddl_Province.Items.Add(li);
                } 
            }
            private void BindCity(string code)
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(Server.MapPath("ChinaArea.xml"));
                XmlNodeList nodelist = xmlDoc.SelectNodes(string.Format("area/province[@provinceID={0}]/City",code)); 
                ListItem li = null;
                foreach (XmlNode myNode in nodelist)
                {
                    li = new ListItem();
                    li.Value = myNode.Attributes["CityID"].Value;
                    li.Text = myNode.Attributes["City"].Value;
                    this.ddl_City.Items.Add(li);
                } 
            }
    
            private void BindArea(string code)
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(Server.MapPath("ChinaArea.xml"));
                XmlNodeList nodelist = xmlDoc.SelectNodes(string.Format("area/province/City[@CityID={0}]/Piecearea",code));
                ListItem li = null;
                foreach (XmlNode myNode in nodelist)
                {
                    li = new ListItem();
                    li.Value = myNode.Attributes["PieceareaID"].Value;
                    li.Text = myNode.Attributes["Piecearea"].Value;
                    this.ddl_Area.Items.Add(li);
                } 
            }
    
            protected void ddl_City_SelectedIndexChanged(object sender, EventArgs e)
            {
                ddl_Area.Items.Clear();
                BindArea(ddl_City.SelectedItem.Value);
            }
    
            protected void ddl_Province_SelectedIndexChanged(object sender, EventArgs e)
            {
                ddl_City.Items.Clear();
                ddl_Area.Items.Clear();
                BindCity(ddl_Province.SelectedItem.Value);
                BindArea(ddl_City.SelectedItem.Value);
            }
            #endregion

     http://www.res.isofteam.com/xml/area.txt

    将连接中的文件保存到ChinaArea.xml中

  • 相关阅读:
    python爬虫入门---第三篇:保存一张图片
    python爬虫入门---第四篇:网站对爬虫的限制及突破测试
    python笔记之字符串
    浅析requests库响应对象的text和content属性
    AOP concepts
    设计模式之组合模式
    装饰者设计模式
    设计模式读书笔记-----桥接模式(转)
    适配器模式
    原型设计模式及深拷贝
  • 原文地址:https://www.cnblogs.com/van0328/p/3672025.html
Copyright © 2020-2023  润新知