Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<script src= "Jquery1.7.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" >
$ (function () {
$.ajax ({
Type: "Post",
ContentType: "Application/json",
URL: "Webservice1.asmx/loadprovince",
Data: "{}",
Success:function (Result) {
var ping;
for (var i = 0; i < result.d.length; i++) {
ping = + "<option value=" + Result.d[i].provinceid + ">";
ping + + result.d[i].provincename;
ping = = "</option>";
}
$ (' #Select1 '). Append (ping);
}
})
$ (' #Select1 '). Change (function () {
The second time, remember to clear the city and county.
$ (' #Select2 option:gt (0) '). Remove ();
$ (' #Select3 option:gt (0) '). Remove ();
Tie down a list of changes in the province (to lose the ID of the province)
$.ajax ({
Type: "Post",
ContentType: "Application/json",
URL: "Webservice1.asmx/loadcity",
Data: "{fatherid: '" + $ (' #Select1 option:selected '). Val () + "'}",
Success:function (Result) {
var str2;
for (var i = 0; i < result.d.length; i++) {
STR2 + + "<option value=" + Result.d[i].cityid + ">";
STR2 + = Result.d[i].cityname;
str2 = "</option>";
}
$ (' #Select2 '). Append (STR2);
}
})
})
$ (' #Select2 '). Change (function () {
$ (' #Select3 option:gt (0) '). Remove ();
$.ajax ({
Type: "Post",
ContentType: "Application/json",
URL: "Webservice1.asmx/loadarea",
Data: "{fatherid: '" + $ (' #Select2 option:selected '). Val () + "'}",
Success:function (Result) {
var str3;
for (var i = 0; i < result.d.length; i++) {
STR3 + + "<option value=" + Result.d.areaid + ">";
STR3 + = Result.d[i].areaname;
STR3 + = Result.d[i].father;
}
$ (' #Select3 '). Append (STR3);
}
})
})
})
</script>
<body>
Province:
<select id= "Select1" >
<option>--Please select--</option>
</select>
City:
<select id= "Select2" >
<option>--Please select--</option>
</select>
County:
<select id= "Select3" >
<option>--Please select--</option>
</select>
</body>
WebService
Copy Code code as follows:
[webmethod]//Loading Province
Public list<model.province> loadprovince () Why should I use List because it's not possible to have a previous value here? An instance is a record that prevents field errors
{
Bll.province bp = new Bll.province ();
List<model.province> List=bp.getlistmodel ();
return list;
}
[webmethod]//Loading City
Public list<model.city> loadcity (string fatherid)
{
bll.city BC = new Bll.city ();
list<model.city> list = Bc.getlistmodel (Fatherid);
return list;
}
[webmethod]//Loading County
Public list<model.area> LoadArea (string fatherid)
{
Bll.area ba = new Bll.area ();
list<model.area> list = Ba.getlistmodel (Fatherid);
return list;
}
}
}
Dal--area
Copy Code code as follows:
Public system.collections.generic.list<model.area> Getlistmodel (string fatherid)
{
system.collections.generic.list<model.area> List = new system.collections.generic.list<model.area> ();
DataTable dt = getlist ("father=" + Fatherid + ""). Tables[0];
foreach (DataRow row in dt. Rows)
{
Model.area ma = new Model.area ();
Ma.areaid = row["Areaid"]. ToString ();
Ma.areaname = row["AreaName"]. ToString ();
Ma.father = row["Father"]. ToString ();
List. ADD (MA);
}
return list;
}
Dal--city
Copy Code code as follows:
Public system.collections.generic.list<model.area> Getlistmodel (string fatherid)
{
system.collections.generic.list<model.area> List = new system.collections.generic.list<model.area> ();
DataTable dt = getlist ("father=" + Fatherid + ""). Tables[0];
foreach (DataRow row in dt. Rows)
{
Model.area ma = new Model.area ();
Ma.areaid = row["Areaid"]. ToString ();
Ma.areaname = row["AreaName"]. ToString ();
Ma.father = row["Father"]. ToString ();
List. ADD (MA);
}
return list;
}
}
Dal-provience
Copy Code code as follows:
Public system.collections.generic.list<model.province> Getlistmodel ()
{
The content to be searched is returned in the form of an instance
Here to do is to create a list and fill the list with the model instance, and the model to use a method to lose data and add to the model
Build List Instance
system.collections.generic.list<model.province> List = new System.collections.generic.list<model.province > ();
There's already a way to lose data without writing it yourself. Manipulate the database to get the data by invoking the GetList method
DataTable dt = GetList (""). Tables[0];
When you get the data, you need to add the data to the model instance.
foreach (DataRow row in dt. Rows)
{
Each row is an instance, so you put the model in the loop.
Model.province MP = new model.province ();
Mp.provinceid = row["Provinceid"]. ToString ();
Mp.provincename = row["Provincename"]. ToString ();
List. Add (MP)//No more than one instance is placed in the list
}
return list;
}