The example of this article for everyone to share the AJAX implementation of no refresh provinces and cities three-level linkage of the specific code for your reference, the specific content as follows
Effect Chart:
Implementation code:
1, HTML:
2, Webservice1.asmx
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.Services; Namespace city and county level three linkage {///<summary>///WebService1 Summary description///</summary> [WebService (Namespace = "http:/ /tempuri.org/")] [webservicebinding (ConformsTo = wsiprofiles.basicprofile1_1)] [System.ComponentModel.ToolboxItem (
FALSE)]//To allow the use of ASP.net AJAX to invoke this Web service from a script, uncomment the downlink. [System.Web.Script.Services.ScriptService] public class WebService1:System.Web.Services.WebService {[Webmetho
D] public string HelloWorld () {return ' Hello world ';
[WebMethod] public list<model.province> getprovince () {bll.province Bpro = new Bll.province (); list<model.province> list = Bpro.
Getlistmodel ();
return list; [WebMethod] public list<model.city> Getcitybypro (string proid) {bll.city bcity = new Bll.city ()
; list<model.city> list = bcity. Getlistmodel ("FatHer= ' "+ proid +" "");
return list; [WebMethod] public list<model.area> getareabycity (string cityid) {Bll.area Barea = new Bll.area
(); list<model.area> list = Barea.
Getlistmodel ("father= '" + Cityid + "");
return list;
}
}
}
Add the following properties to the City.cs and Area.cs in the three-layer BLL layer
City.cs: Public
list<model.city> Getlistmodel (string strSQL)
{return
dal. Getlistmodel (strSQL);
}
Area.cs: Public
list<model.area> Getlistmodel (string strSQL)
{return
dal. Getlistmodel (strSQL);
}
Add the following methods to the City.cs and Area.cs in the three-layer dal layer, respectively
City.cs:public system.collections.generic.list<model.city> Getlistmodel (string strsql) {System.collec tions.
generic.list<model.city> List = new system.collections.generic.list<model.city> (); DataTable dt = GetList (strSQL).
Tables[0]; foreach (DataRow row in dt.
Rows) {model.city mcity = new model.city ();
Mcity.id = Convert.ToInt32 (row["id")); Mcity.cityid = row["Cityid"].
ToString (); Mcity.cityname = row["CityName"].
ToString (); List.
ADD (mcity);
} return list; }//area.cs:public system.collections.generic.list<model.area> Getlistmodel (string strsql) {DataTable DT = GetList (strSQL).
Tables[0];
system.collections.generic.list<model.area> List = new system.collections.generic.list<model.area> (); foreach (DataRow row in dt. Rows) {Model.area Marea = new Model.area () {id = Convert.ToInt32 (row["id"]), a ReaID = row["Areaid"]. ToString (), areaname = row["AreaName"].
ToString ()}; List.
ADD (Marea);
} return list; }
The above is the entire content of this article, I hope to help you learn.