Ajax implementation of no refresh provinces, cities and counties three-level linkage _ajax related

Source: Internet
Author: User

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.

Related Article

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.