这类东西很多人都写过,但我是第一次写,支持一下菜鸟的原创吧~
第一级是写死的(因为省不会变的),以下三级都是现查的数据库,由于没有采用DIV格式,所以有些ID很长~
js代码:
1function ProvinceChange(obj1,obj2,obj3)
    2 {
    3         if( typeof(ActiveXObject) != "undefined")
    4        {
    5                 if(obj1.value=="")
    6                {
    7                        obj2.length=0;
    8                        obj3.length=0;
    9                        form1.Wizard1_SchoolAddForm1_District.length=0;
10                }
11                 else
12                {
13                        xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP");
14                         var item = obj1.options[obj1.selectedIndex].value;
15                         var ReqStr = '<?xml version= "1.0"?>';                    
16                        xmlHttp.open( "GET", "SettleForm.aspx?province="+item);
17                        xmlHttp.send(ReqStr);
18                        xmlHttp.onreadystatechange = HandleResult;
19                }
20        }
21         function HandleResult()
22        {
23             if(4 == xmlHttp.readyState || "complete" == xmlHttp.readyState)
24             {
25                        obj2.length=0;
26                        obj3.length=0;
27                        form1.Wizard1_SchoolAddForm1_District.length=0;
28                        obj2.options[obj2.length]= new Option("");
29                        obj3.options[obj3.length]= new Option("");
30                         var e=xmlHttp.responseText;
31                        alert(e);
32                         if(e!= "未添加")
33                        {
34                                 var a=e.split( "*");
35                                 var arr1=a[0].toString().split( ",");
36                                 var arr2=a[1].toString().split( ",");
37                                 for( var i=0;i<arr1.length;i++)
38                                {                                                
39                                        obj2.options[obj2.length]= new Option(arr1[i]);
40                                }
41                                 for( var j=0;j<arr2.length;j++)
42                                {                                                
43                                        obj3.options[obj3.length]= new Option(arr2[j]);
44                                }
45                        }
46             }
47        }
48 }
49    
50 function CityChange(obj1,obj2,obj3)
51 {
52         if( typeof(ActiveXObject) != "undefined")
53        {
54                 if(obj1.selectedIndex==0)
55                {
56                         obj2.length=0;
57                         obj3.length=0;
58                }
59                 else
60                {
61                        xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP");
62                         var ReqStr = '<?xml version= "1.0"?>';    
63                         var item = obj1.options[obj1.selectedIndex].text;                
64                        xmlHttp.open( "GET", "SettleForm.aspx?city="+item);
65                        xmlHttp.send(ReqStr);
66                        xmlHttp.onreadystatechange = HandleResult;
67                }
68        }
69         function HandleResult()
70        {
71             if(4 == xmlHttp.readyState || "complete" == xmlHttp.readyState)
72             {
73                        obj2.length=0;
74                        obj2.options[obj2.length]= new Option("");
75                        obj3.length=0;
76                        obj3.options[obj3.length]= new Option("");
77                         var e=xmlHttp.responseText;
78                         if(e!= "未添加")
79                        {
80                                 var a=e.split( "*");
81                                 var arr1=a[0].toString().split( ",");
82                                 var arr2=a[1].toString().split( ",");
83                                 for( var i=0;i<arr1.length;i++)
84                                {                                                
85                                        obj2.options[obj2.length]= new Option(arr1[i]);
86                                }
87                                 for( var j=0;j<arr2.length;j++)
88                                {                                                
89                                        obj3.options[obj3.length]= new Option(arr2[j]);
90                                }
91                        }    
92             }
93        }
94    
95 }
96    
97 function DistrictChange(obj1,obj2)
98 {
99         if( typeof(ActiveXObject) != "undefined")
100        {
101                 if(obj1.selectedIndex==0)
102                {
103                         obj2.length=0;
104                }
105                 else
106                {
107                        xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP");
108                         var item = obj1.options[obj1.selectedIndex].text;
109                         var ReqStr = '<?xml version= "1.0"?>';                    
110                        xmlHttp.open( "GET", "SettleForm.aspx?district="+item);
111                        xmlHttp.send(ReqStr);
112                        xmlHttp.onreadystatechange = HandleResult;
113                }
114        }
115         function HandleResult()
116        {
117             if(4 == xmlHttp.readyState || "complete" == xmlHttp.readyState)
118             {
119                        obj2.length=0;
120                        obj2.options[obj2.length]= new Option("");
121                         if(e!= "未添加")
122                        {
123                                 var e=xmlHttp.responseText;
124                                 var arr=e.split( ",")
125                                 for( var i=0;i<arr.length;i++)
126                                {                                                
127                                        obj2.options[obj2.length]= new Option(arr[i]);
128                                }
129                        }
130             }
131        }
132 }
133
 
中间页代码:
InBlock.gif public partial class BusinessmanManage_SettleForm : System.Web.UI.Page
InBlock.gif 19{
InBlock.gif 20         protected ShoppingChain.BLL.Product p = new ShoppingChain.BLL.Product();
InBlock.gif 21         protected ShoppingChain.BLL.Register r = new ShoppingChain.BLL.Register();
InBlock.gif 22         protected void Page_Load( object sender, EventArgs e)
InBlock.gif 23        {
InBlock.gif 24                         if (Request.QueryString[ "province"] != null)
InBlock.gif 25                {
InBlock.gif 26                        IList<SchoolInfo> list1 = r.GetCityByProvince(Request.QueryString[ "province"]);
InBlock.gif 27                        IList<SchoolInfo> list2 = r.GetSchoolByProvince(Request.QueryString[ "province"]);
InBlock.gif 28                         if (list1.Count == 0)
InBlock.gif 29                        {
InBlock.gif 30                                Response.Write( "未添加");
InBlock.gif 31                        }
InBlock.gif 32                         else
InBlock.gif 33                        {
InBlock.gif 34                                 //string cityshort = "";
InBlock.gif 35                                 string cityname = "";
InBlock.gif 36                                 string school = "";
InBlock.gif 37                                 foreach (SchoolInfo info in list1)
InBlock.gif 38                                {
InBlock.gif 39                                        cityname = cityname + info.City + ",";
InBlock.gif 40                                }
InBlock.gif 41                                 //string str = cityshort.Remove(cityshort.Length - 1);
InBlock.gif 42                                 string strcname = cityname.Remove(cityname.Length - 1);
InBlock.gif 43                                 foreach (SchoolInfo info in list2)
InBlock.gif 44                                {
InBlock.gif 45                                        school = school + info.School + ",";
InBlock.gif 46                                }
InBlock.gif 47                                 string strschool = school.Remove(school.Length - 1);
InBlock.gif 48                                 string s = strcname + "*" + strschool;
InBlock.gif 49                                Response.Write(s);
InBlock.gif 50                        }
InBlock.gif 51                }
InBlock.gif 52                 if (Request.QueryString[ "city"] != null)
InBlock.gif 53                {
InBlock.gif 54                        IList<SchoolInfo> list1 = r.GetDistrictByCity(Request.QueryString[ "city"]);
InBlock.gif 55                        IList<SchoolInfo> list2 = r.GetSchoolByCity(Request.QueryString[ "city"]);
InBlock.gif 56                         string district = "";
InBlock.gif 57                         string school = "";
InBlock.gif 58                         if (list1.Count == 0)
InBlock.gif 59                        {
InBlock.gif 60                                Response.Write( "未添加");
InBlock.gif 61                        }
InBlock.gif 62                         else
InBlock.gif 63                        {
InBlock.gif 64                                 foreach (SchoolInfo info in list1)
InBlock.gif 65                                {
InBlock.gif 66                                        district = district + info.District + ",";
InBlock.gif 67                                }
InBlock.gif 68                                 string strdistrict = district.Remove(district.Length - 1);
InBlock.gif 69
InBlock.gif 70                                 foreach (SchoolInfo info in list2)
InBlock.gif 71                                {
InBlock.gif 72                                        school = school + info.School + ",";
InBlock.gif 73                                }
InBlock.gif 74                                 string strschool = school.Remove(school.Length - 1);
InBlock.gif 75
InBlock.gif 76                                 string s = strdistrict + "*" + strschool;
InBlock.gif 77                                Response.Write(s);
InBlock.gif 78                        }
InBlock.gif 79                }
InBlock.gif 80                 if (Request.QueryString[ "district"] != null)
InBlock.gif 81                {
InBlock.gif 82                        IList<SchoolInfo> list = r.GetSchoolByDistrict(Request.QueryString[ "district"]);
InBlock.gif 83                         if (list.Count == 0)
InBlock.gif 84                        {
InBlock.gif 85                                Response.Write( "未添加");
InBlock.gif 86                        }
InBlock.gif 87                         else
InBlock.gif 88                        {
InBlock.gif 89                                 string schoolname = "";
InBlock.gif 90                                 foreach (SchoolInfo info in list)
InBlock.gif 91                                {
InBlock.gif 92                                        schoolname = schoolname + info.School + ",";
InBlock.gif 93                                }
InBlock.gif 94                                 string strschool = schoolname.Remove(schoolname.Length - 1);
InBlock.gif 95                                Response.Write(strschool);
InBlock.gif 96                        }
InBlock.gif 97                }
InBlock.gif 98        }
InBlock.gif 99}