 
 
网页前台代码:
 <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default"  EnableEventValidation="false"%>
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default"  EnableEventValidation="false"%>
 <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">
<head runat="server"> <title>无标题页</title>
    <title>无标题页</title> </head>
</head> <body>
<body> <form id="form1" runat="server">
    <form id="form1" runat="server"> <div align="center">
    <div align="center"> <asp:ScriptManager ID="ScriptManager1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
        </asp:ScriptManager> <fieldset >
    <fieldset > <legend>全国省市县</legend>
    <legend>全国省市县</legend> <fieldset style="width: 265px">
    <fieldset style="width: 265px"> <legend>省</legend>
    <legend>省</legend> <asp:DropDownList ID="DropDownList1" runat="server"
                    <asp:DropDownList ID="DropDownList1" runat="server"  AutoPostBack="True">
            AutoPostBack="True"> </asp:DropDownList>
                    </asp:DropDownList> <cc1:CascadingDropDown ID="DropDownList1_CascadingDropDown" runat="server"
                    <cc1:CascadingDropDown ID="DropDownList1_CascadingDropDown" runat="server"  Category="provice" Enabled="True" LoadingText="读取数据中
                        Category="provice" Enabled="True" LoadingText="读取数据中 .." PromptText="请选择省"
.." PromptText="请选择省"  TargetControlID="DropDownList1" ServicePath="WebService.asmx" ServiceMethod="GetproviceNames">
                        TargetControlID="DropDownList1" ServicePath="WebService.asmx" ServiceMethod="GetproviceNames"> </cc1:CascadingDropDown>
                    </cc1:CascadingDropDown> </fieldset>
    </fieldset> <fieldset style="width: 266px">
        <fieldset style="width: 266px"> <legend>市</legend>
    <legend>市</legend> <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True">
                    <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"> </asp:DropDownList>
                    </asp:DropDownList> <cc1:CascadingDropDown ID="DropDownList2_CascadingDropDown" runat="server"
                    <cc1:CascadingDropDown ID="DropDownList2_CascadingDropDown" runat="server"  Category="city" Enabled="True" TargetControlID="DropDownList2" LoadingText="读取数据中
                        Category="city" Enabled="True" TargetControlID="DropDownList2" LoadingText="读取数据中 .." PromptText="请选择市" ParentControlID="DropDownList1"
.." PromptText="请选择市" ParentControlID="DropDownList1" ServicePath="WebService.asmx" ServiceMethod="GetCityNames">
                          ServicePath="WebService.asmx" ServiceMethod="GetCityNames"> </cc1:CascadingDropDown>
                    </cc1:CascadingDropDown> </fieldset>
    </fieldset> <fieldset style="width: 266px">
            <fieldset style="width: 266px"> <legend>县</legend>
    <legend>县</legend> <asp:DropDownList ID="DropDownList3" runat="server">
                <asp:DropDownList ID="DropDownList3" runat="server"> </asp:DropDownList>
                </asp:DropDownList> <cc1:CascadingDropDown ID="DropDownList3_CascadingDropDown" runat="server"  Category="District" TargetControlID="DropDownList3"
                <cc1:CascadingDropDown ID="DropDownList3_CascadingDropDown" runat="server"  Category="District" TargetControlID="DropDownList3" Enabled="True" LoadingText="读取数据中
                    Enabled="True" LoadingText="读取数据中 .." ParentControlID="DropDownList2"
.." ParentControlID="DropDownList2" ServicePath="WebService.asmx" ServiceMethod="GetDistrictNames">
                    ServicePath="WebService.asmx" ServiceMethod="GetDistrictNames"> </cc1:CascadingDropDown>
                </cc1:CascadingDropDown> </fieldset>
    </fieldset> </fieldset>
 </fieldset>
 </div>
    </div> </form>
    </form> </body>
</body> </html>
</html>
 using System;
using System; using System.Collections;
using System.Collections; using System.Linq;
using System.Linq; using System.Web;
using System.Web; using System.Web.Services;
using System.Web.Services; using System.Web.Services.Protocols;
using System.Web.Services.Protocols; using System.Xml.Linq;
using System.Xml.Linq;
 //访问数据库命名空间
//访问数据库命名空间 using System.Data;
using System.Data; using System.Data.SqlClient;
using System.Data.SqlClient;
 //访问web.config命名空间
//访问web.config命名空间 using System.Web.Configuration;
using System.Web.Configuration;
 //导入ScriptServiceAttribute类的命名空间
//导入ScriptServiceAttribute类的命名空间 using System.Web.Script.Services;
using System.Web.Script.Services;
 //返回CascadingDropDownNameValue数组所需的命名空间
//返回CascadingDropDownNameValue数组所需的命名空间 using AjaxControlToolkit;
using AjaxControlToolkit; using System.Collections.Generic;
using System.Collections.Generic; using System.Collections.Specialized;
using System.Collections.Specialized;
 /// <summary>
/// <summary> ///WebService 的摘要说明
///WebService 的摘要说明 /// </summary>
/// </summary> [WebService(Namespace = "http://tempuri.org/")]
[WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] //若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。  [System.Web.Script.Services.ScriptService]
[System.Web.Script.Services.ScriptService] public class WebService : System.Web.Services.WebService
public class WebService : System.Web.Services.WebService {
{
 public WebService()
    public WebService() {
    {
 //如果使用设计的组件,请取消注释以下行
        //如果使用设计的组件,请取消注释以下行  //InitializeComponent();
        //InitializeComponent();  }
    }
 [WebMethod]
    [WebMethod] public CascadingDropDownNameValue[] GetproviceNames(string knownCategoryValues, string category)
    public CascadingDropDownNameValue[] GetproviceNames(string knownCategoryValues, string category) {
    { List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
        List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>(); SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["Personal"].ConnectionString);
        SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["Personal"].ConnectionString); SqlCommand comm = conn.CreateCommand();
        SqlCommand comm = conn.CreateCommand(); comm.CommandText = "select [ProvinceID],[ProvinceName] from [S_Province] order by 1";
        comm.CommandText = "select [ProvinceID],[ProvinceName] from [S_Province] order by 1"; conn.Open();
        conn.Open(); try
        try {
        { SqlDataReader dr = comm.ExecuteReader();
            SqlDataReader dr = comm.ExecuteReader(); while (dr.Read())
            while (dr.Read()) {
            { values.Add(new CascadingDropDownNameValue(dr[1].ToString(), dr[0].ToString()));
                values.Add(new CascadingDropDownNameValue(dr[1].ToString(), dr[0].ToString())); }
            } return values.ToArray();
            return values.ToArray(); }
        } finally
        finally {
        { conn.Close();
            conn.Close(); }
        } }
    } [WebMethod]
    [WebMethod] public CascadingDropDownNameValue[] GetCityNames(string knownCategoryValues, string category)
    public CascadingDropDownNameValue[] GetCityNames(string knownCategoryValues, string category) {
    { StringDictionary kcv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        StringDictionary kcv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); if (!kcv.ContainsKey("provice"))
        if (!kcv.ContainsKey("provice")) {
        { return null;
            return null; }
        } List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
        List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>(); SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["Personal"].ConnectionString);
        SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["Personal"].ConnectionString); SqlCommand comm = conn.CreateCommand();
        SqlCommand comm = conn.CreateCommand(); comm.CommandText = "select [CityID],[CityName] from [S_City] where [ProvinceID]=@ProvinceID order by 1";
        comm.CommandText = "select [CityID],[CityName] from [S_City] where [ProvinceID]=@ProvinceID order by 1"; comm.Parameters.Add("@ProvinceID", SqlDbType.Int).Value = kcv["provice"];
        comm.Parameters.Add("@ProvinceID", SqlDbType.Int).Value = kcv["provice"]; conn.Open();
        conn.Open(); try
        try {
        { SqlDataReader dr = comm.ExecuteReader();
            SqlDataReader dr = comm.ExecuteReader(); while (dr.Read())
            while (dr.Read()) {
            { values.Add(new CascadingDropDownNameValue(dr[1].ToString(), dr[0].ToString()));
                values.Add(new CascadingDropDownNameValue(dr[1].ToString(), dr[0].ToString())); }
            } return values.ToArray();
            return values.ToArray(); }
        } finally
        finally {
        { conn.Close();
            conn.Close(); }
        } }
    } [WebMethod]
    [WebMethod] public CascadingDropDownNameValue[] GetDistrictNames(string knownCategoryValues, string category)
    public CascadingDropDownNameValue[] GetDistrictNames(string knownCategoryValues, string category) {
    { StringDictionary kcv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        StringDictionary kcv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); if (!kcv.ContainsKey("city"))
        if (!kcv.ContainsKey("city")) {
        { return null;
            return null; }
        } List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
        List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>(); SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["Personal"].ConnectionString);
        SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["Personal"].ConnectionString); SqlCommand comm = conn.CreateCommand();
        SqlCommand comm = conn.CreateCommand(); comm.CommandText = "select [DistrictID],[DistrictName] from [S_District] where [CityID]=@CityID order by 1";
        comm.CommandText = "select [DistrictID],[DistrictName] from [S_District] where [CityID]=@CityID order by 1"; comm.Parameters.Add("@CityID", SqlDbType.Int).Value = kcv["city"];
        comm.Parameters.Add("@CityID", SqlDbType.Int).Value = kcv["city"]; conn.Open();
        conn.Open(); try
        try {
        { SqlDataReader dr = comm.ExecuteReader();
            SqlDataReader dr = comm.ExecuteReader(); while (dr.Read())
            while (dr.Read()) {
            { values.Add(new CascadingDropDownNameValue(dr[1].ToString(), dr[0].ToString()));
                values.Add(new CascadingDropDownNameValue(dr[1].ToString(), dr[0].ToString())); }
            } return values.ToArray();
            return values.ToArray(); }
        } finally
        finally {
        { conn.Close();
            conn.Close(); }
        } }
    } }
}

数据库脚本下载地址: https://files.cnblogs.com/yechensi/PCD_AllData_V1.rar
 
                    
                 

 
     
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号