<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    XmlHttp實現(xiàn)無刷新三聯(lián)動下拉框


    1.html代碼

    <HTML>
        <HEAD>
            <title>XmlHttp實現(xiàn)無刷新三聯(lián)動下拉框</title>
            <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
            <meta name="CODE_LANGUAGE" Content="C#">
            <meta name="vs_defaultClientScript" content="JavaScript">
            <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
        </HEAD>
        <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
                <INPUT style="Z-INDEX: 102; LEFT: 448px; WIDTH: 56px; POSITION: absolute; TOP: 80px; HEIGHT: 24px"
                    onclick="getData();" type="button" value="保存" id="Button1" name="Button1" runat="server">
                <asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 80px" runat="server"
                    Width="424px"></asp:TextBox>
                <asp:DropDownList id="DropDownList2" runat="server" style="Z-INDEX: 103; LEFT: 176px; POSITION: absolute; TOP: 120px"></asp:DropDownList>
                <asp:DropDownList id="DropDownList1" runat="server" style="Z-INDEX: 104; LEFT: 16px; POSITION: absolute; TOP: 120px"></asp:DropDownList>
                <asp:DropDownList id="DropDownList3" runat="server" style="Z-INDEX: 105; LEFT: 296px; POSITION: absolute; TOP: 120px"></asp:DropDownList><INPUT style="Z-INDEX: 106; LEFT: 8px; WIDTH: 160px; POSITION: absolute; TOP: 176px; HEIGHT: 22px"
                    type="hidden" size="21" id="hidprovince" runat="server"><INPUT style="Z-INDEX: 107; LEFT: 184px; POSITION: absolute; TOP: 176px" type="hidden"
                    id="hidcity" runat="server"><INPUT style="Z-INDEX: 108; LEFT: 360px; POSITION: absolute; TOP: 176px" type="hidden"
                    id="hidarea" runat="server">
                <SCRIPT LANGUAGE="JavaScript">
                <!--
                    //以XML求取DropDownList2的數(shù)據(jù)
                    function XmlPost2(obj)
                    {
                      var svalue = obj.value;
                      var webFileUrl = "?povinceid=" + svalue;
                      var result = "";
                      var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
                      xmlHttp.open("POST", webFileUrl, false);
                      xmlHttp.send("");
                      result = xmlHttp.responseText;
                      
                      if(result != "")
                      {
                        document.all("DropDownList2").length=0;
                        var piArray = result.split(",");
                        for(var i=0;i<piArray.length;i++)
                        {
                          var ary1 = piArray[i].toString().split("|");
                          document.all("DropDownList2").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
                        }
                      }
                      else
                      {
                        alert(result);
                      }
                    }
                    //以XML求取DropDownList3的數(shù)據(jù)
                    function XmlPost3(obj)
                    {
                      var svalue = obj.value;
                      var webFileUrl = "?cityid=" + svalue;
                      var result = "";
                      var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
                      xmlHttp.open("POST", webFileUrl, false);
                      xmlHttp.send("");
                      result = xmlHttp.responseText;
                      
                      if(result != "")
                      {
                        document.all("DropDownList3").length=0;
                        var piArray = result.split(",");
                        for(var i=0;i<piArray.length;i++)
                        {
                          var ary1 = piArray[i].toString().split("|");
                          document.all("DropDownList3").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
                        }
                      }
                      else
                      {
                        alert(result);
                      }
                    }
                    function getData()
                    {
                        var province=document.getElementById("DropDownList1");
                        var pindex = province.selectedIndex;
                        var pValue = province.options[pindex].value;
                        var pText  = province.options[pindex].text;
                        
                        var city=document.getElementById("DropDownList2");
                        var cindex = city.selectedIndex;
                        var cValue = city.options[cindex].value;
                        var cText  = city.options[cindex].text;
                        
                        var area=document.getElementById("DropDownList3");
                        var aindex = area.selectedIndex;
                        var aValue = area.options[aindex].value;
                        var aText  = area.options[aindex].text;
                        
                        var txt=document.getElementById("TextBox1");                                

                        document.getElementById("<%=TextBox1.ClientID%>").innerText="省:"+pValue+"|"+pText+"市:"+cValue+"|"+cText+"區(qū):"+aValue+"|"+aText;
                        document.Form1.hidprovince.value=pValue;
                        document.Form1.hidcity.value=cValue;
                        document.Form1.hidarea.value=aValue;
                    }
                //-->
                </SCRIPT>
            </form>
        </body>
    </HTML>

    2.cs代碼

    public class WebForm1 : System.Web.UI.Page
        {
            protected System.Web.UI.WebControls.DropDownList DropDownList1;
            protected System.Web.UI.WebControls.DropDownList DropDownList2;
            protected System.Web.UI.WebControls.DropDownList DropDownList3;
            protected System.Web.UI.WebControls.TextBox TextBox1;
        
            public static string ConnectionString=System.Configuration .ConfigurationSettings .AppSettings["ConnectionString"];
        
            GetDataSet#region GetDataSet
            public static DataSet GetDataSet(string sql)
            {
                SqlDataAdapter    sda =new SqlDataAdapter(sql,ConnectionString);
                DataSet ds=new DataSet();
                sda.Fill(ds);
                return ds;
            }
            #endregion

            property#region property
            private string provinceid
            {
                get
                {
                    if(ViewState["provinceid"]!=null && ViewState["provinceid"].ToString()!="")
                    {
                        return ViewState["provinceid"].ToString();
                    }
                    else
                    {
                        if(Request["provinceid"]!=null && Request["provinceid"].ToString()!="")
                        {
                            return Request["provinceid"];
                        }
                        else
                        {
                            return "";
                        }
                    }
                }
                set
                {
                    ViewState["provinceid"]=value;
                }
            }
            private string cityid
            {
                get
                {
                    if(ViewState["cityid"]!=null && ViewState["cityid"].ToString()!="")
                    {
                        return ViewState["cityid"].ToString();
                    }
                    else
                    {
                        if(Request["cityid"]!=null && Request["cityid"].ToString()!="")
                        {
                            return Request["cityid"];
                        }
                        else
                        {
                            return "";
                        }
                    }
                }
                set
                {
                    ViewState["cityid"]=value;
                }
            }
            #endregion

            Page_Load#region Page_Load
            private void Page_Load(object sender, System.EventArgs e)
            {
                if(!this.IsPostBack)
              {
                this.down1_bind();
                    this.DropDownList1.Attributes.Add("onchange","XmlPost2(this);");
                    this.DropDownList2.Attributes.Add("onchange","XmlPost3(this);");
              }
              if(provinceid != "")
              {
                this.down2_bind(provinceid);
              }
                if(cityid != "")
              {
                this.down3_bind(cityid);
              }
            }
            
            #endregion

            down2_bind#region down2_bind
            private void down2_bind(string id)
            {
              string mystr = "";
              string sql = "select cityID,city from city where father = '" + id + "'";
              DataSet ds = GetDataSet(sql);

              if(ds.Tables[0].Rows.Count != 0)
              {
                for(int i=0;i<ds.Tables[0].Rows.Count;i++)
                {
                  mystr += "," + ds.Tables[0].Rows[i][0].ToString() + "|" + ds.Tables[0].Rows[i][1].ToString();
                }
                mystr = mystr.Substring(1);
              }
              this.Response.Write(mystr);
              this.Response.End();
            }
            #endregion

            down3_bind#region down3_bind
            private void down3_bind(string id)
            {
              string mystr = "";
              string sql = "select areaID,area from area where father = '" + id + "'";
              DataSet ds = GetDataSet(sql);

              if(ds.Tables[0].Rows.Count != 0)
              {
                for(int i=0;i<ds.Tables[0].Rows.Count;i++)
                {
                  mystr += "," + ds.Tables[0].Rows[i][0].ToString() + "|" + ds.Tables[0].Rows[i][1].ToString();
                }
                mystr = mystr.Substring(1);
              }
              this.Response.Write(mystr);
              this.Response.End();
            }

            #endregion
            
            down1_bind#region down1_bind
            private void down1_bind()
            {
              string sql = "select provinceID,province from province";
              DataSet ds = GetDataSet(sql);
              this.DropDownList1.DataSource = ds;
              this.DropDownList1.DataValueField = "provinceID";
              this.DropDownList1.DataTextField = "province";
              this.DropDownList1.DataBind();          
            }

            #endregion

            Web Form Designer generated code#region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
            {
                //
                // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                //
                InitializeComponent();
                base.OnInit(e);
            }

            /**//// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {    
                this.Load += new System.EventHandler(this.Page_Load);

            }
            #endregion
        }

    3.數(shù)據(jù)庫area1.rar
    4.Ajax實現(xiàn)無刷新三聯(lián)動下拉框

    5.源代碼下載XmlHttpselect.rar


    posted on 2007-06-20 13:33 chenguo 閱讀(283) 評論(0)  編輯  收藏 所屬分類: AJAX Dev

    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導(dǎo)航

    統(tǒng)計

    留言簿

    隨筆分類(1)

    文章分類(52)

    好友 小山的博客

    最新隨筆

    最新評論

    主站蜘蛛池模板: 久久精品国产免费观看三人同眠| 亚洲电影免费在线观看| 黄色网址免费大全| www成人免费视频| 亚洲日韩精品无码专区加勒比☆| 亚洲国产精品婷婷久久| 久久精品夜色噜噜亚洲A∨| 热99re久久免费视精品频软件| 亚洲香蕉免费有线视频| 国产一二三四区乱码免费| 美女视频黄a视频全免费网站色| 亚洲国产精品免费观看| 亚洲国产综合在线| 亚洲免费视频网站| 久久亚洲精品成人综合| 亚洲欧洲自拍拍偷午夜色无码| 亚洲男人在线无码视频| 波多野结衣免费视频观看| 成人a视频片在线观看免费| 在线视频精品免费| 亚洲精品国产免费| **俄罗斯毛片免费| 久久永久免费人妻精品下载| 午夜无码A级毛片免费视频| 青青操在线免费观看| 亚洲精品黄色视频在线观看免费资源 | 亚洲 综合 国产 欧洲 丝袜| 在线观着免费观看国产黄| 最近中文字幕mv免费高清电影 | 久久久久亚洲av无码专区导航| 国产亚洲人成网站观看| 亚洲色欲久久久综合网东京热| 国产亚洲欧洲Aⅴ综合一区| 亚洲综合在线另类色区奇米| 91麻豆国产自产在线观看亚洲| 区三区激情福利综合中文字幕在线一区亚洲视频1 | 成人亚洲性情网站WWW在线观看| 亚洲精品国产福利一二区| 区久久AAA片69亚洲| 国产亚洲精品精华液| 亚洲成a人片在线观看日本|