Ajax achieves three-level linkage between cities and counties in the new province without any need,
The examples in this article share with you the code for implementing the three-level linkage between cities, counties, and cities for your reference. The specific content is as follows:
:
Implementation Code:
1. html:
<Html>
2. WebService1.asmx
Using System; using System. collections. generic; using System. linq; using System. web; using System. web. services; namespace provincial/County Level 3 linkage {// <summary> // summary of WebService1 /// </summary> [WebService (Namespace =" http://tempuri.org/ ")] [WebServiceBinding (ConformsTo = WsiProfiles. basicProfile1_1)] [System. componentModel. toolboxItem (false)] // to allow ASP. net ajax calls this Web service from the script. Please cancel the comments to the downstream. [System. web. script. services. scriptService] public class WebService1: System. web. services. webService {[WebMethod] 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 attributes to city. cs and area. cs in The Bll layer on the third 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 city. cs and area. cs in the three-tier DAL layer:
//city.cs:public System.Collections.Generic.List<Model.city> GetListModel(string strsql) { System.Collections.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"]), areaID = row["areaID"].ToString(), areaname = row["areaname"].ToString() }; list.Add(marea); } return list; }
The above is all the content of this article, hoping to help you learn.