Ajax achieves three-level linkage between cities and counties in the new province without any need,

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.