全国省市县三级联动(数据完整版)
来源:互联网 发布:mac键位 编辑:程序博客网 时间:2024/04/28 12:49
网页前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="false"%>
<%@ 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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<fieldset >
<legend>全国省市县</legend>
<fieldset style="width: 265px">
<legend>省</legend>
<asp:DropDownList ID="DropDownList1" runat="server"
AutoPostBack="True">
</asp:DropDownList>
<cc1:CascadingDropDown ID="DropDownList1_CascadingDropDown" runat="server"
Category="provice" Enabled="True" LoadingText="读取数据中.." PromptText="请选择省"
TargetControlID="DropDownList1" ServicePath="WebService.asmx" ServiceMethod="GetproviceNames">
</cc1:CascadingDropDown>
</fieldset>
<fieldset style="width: 266px">
<legend>市</legend>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True">
</asp:DropDownList>
<cc1:CascadingDropDown ID="DropDownList2_CascadingDropDown" runat="server"
Category="city" Enabled="True" TargetControlID="DropDownList2" LoadingText="读取数据中.." PromptText="请选择市" ParentControlID="DropDownList1"
ServicePath="WebService.asmx" ServiceMethod="GetCityNames">
</cc1:CascadingDropDown>
</fieldset>
<fieldset style="width: 266px">
<legend>县</legend>
<asp:DropDownList ID="DropDownList3" runat="server">
</asp:DropDownList>
<cc1:CascadingDropDown ID="DropDownList3_CascadingDropDown" runat="server" Category="District" TargetControlID="DropDownList3"
Enabled="True" LoadingText="读取数据中.." ParentControlID="DropDownList2"
ServicePath="WebService.asmx" ServiceMethod="GetDistrictNames">
</cc1:CascadingDropDown>
</fieldset>
</fieldset>
</div>
</form>
</body>
</html>
<%@ 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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<fieldset >
<legend>全国省市县</legend>
<fieldset style="width: 265px">
<legend>省</legend>
<asp:DropDownList ID="DropDownList1" runat="server"
AutoPostBack="True">
</asp:DropDownList>
<cc1:CascadingDropDown ID="DropDownList1_CascadingDropDown" runat="server"
Category="provice" Enabled="True" LoadingText="读取数据中.." PromptText="请选择省"
TargetControlID="DropDownList1" ServicePath="WebService.asmx" ServiceMethod="GetproviceNames">
</cc1:CascadingDropDown>
</fieldset>
<fieldset style="width: 266px">
<legend>市</legend>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True">
</asp:DropDownList>
<cc1:CascadingDropDown ID="DropDownList2_CascadingDropDown" runat="server"
Category="city" Enabled="True" TargetControlID="DropDownList2" LoadingText="读取数据中.." PromptText="请选择市" ParentControlID="DropDownList1"
ServicePath="WebService.asmx" ServiceMethod="GetCityNames">
</cc1:CascadingDropDown>
</fieldset>
<fieldset style="width: 266px">
<legend>县</legend>
<asp:DropDownList ID="DropDownList3" runat="server">
</asp:DropDownList>
<cc1:CascadingDropDown ID="DropDownList3_CascadingDropDown" runat="server" Category="District" TargetControlID="DropDownList3"
Enabled="True" LoadingText="读取数据中.." ParentControlID="DropDownList2"
ServicePath="WebService.asmx" ServiceMethod="GetDistrictNames">
</cc1:CascadingDropDown>
</fieldset>
</fieldset>
</div>
</form>
</body>
</html>
WebService代码
using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
//访问数据库命名空间
using System.Data;
using System.Data.SqlClient;
//访问web.config命名空间
using System.Web.Configuration;
//导入ScriptServiceAttribute类的命名空间
using System.Web.Script.Services;
//返回CascadingDropDownNameValue数组所需的命名空间
using AjaxControlToolkit;
using System.Collections.Generic;
using System.Collections.Specialized;
/**//// <summary>
///WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
public WebService()
{
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public CascadingDropDownNameValue[] GetproviceNames(string knownCategoryValues, string category)
{
List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["Personal"].ConnectionString);
SqlCommand comm = conn.CreateCommand();
comm.CommandText = "select [ProvinceID],[ProvinceName] from [S_Province] order by 1";
conn.Open();
try
{
SqlDataReader dr = comm.ExecuteReader();
while (dr.Read())
{
values.Add(new CascadingDropDownNameValue(dr[1].ToString(), dr[0].ToString()));
}
return values.ToArray();
}
finally
{
conn.Close();
}
}
[WebMethod]
public CascadingDropDownNameValue[] GetCityNames(string knownCategoryValues, string category)
{
StringDictionary kcv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
if (!kcv.ContainsKey("provice"))
{
return null;
}
List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["Personal"].ConnectionString);
SqlCommand comm = conn.CreateCommand();
comm.CommandText = "select [CityID],[CityName] from [S_City] where [ProvinceID]=@ProvinceID order by 1";
comm.Parameters.Add("@ProvinceID", SqlDbType.Int).Value = kcv["provice"];
conn.Open();
try
{
SqlDataReader dr = comm.ExecuteReader();
while (dr.Read())
{
values.Add(new CascadingDropDownNameValue(dr[1].ToString(), dr[0].ToString()));
}
return values.ToArray();
}
finally
{
conn.Close();
}
}
[WebMethod]
public CascadingDropDownNameValue[] GetDistrictNames(string knownCategoryValues, string category)
{
StringDictionary kcv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
if (!kcv.ContainsKey("city"))
{
return null;
}
List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["Personal"].ConnectionString);
SqlCommand comm = conn.CreateCommand();
comm.CommandText = "select [DistrictID],[DistrictName] from [S_District] where [CityID]=@CityID order by 1";
comm.Parameters.Add("@CityID", SqlDbType.Int).Value = kcv["city"];
conn.Open();
try
{
SqlDataReader dr = comm.ExecuteReader();
while (dr.Read())
{
values.Add(new CascadingDropDownNameValue(dr[1].ToString(), dr[0].ToString()));
}
return values.ToArray();
}
finally
{
conn.Close();
}
}
}
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
//访问数据库命名空间
using System.Data;
using System.Data.SqlClient;
//访问web.config命名空间
using System.Web.Configuration;
//导入ScriptServiceAttribute类的命名空间
using System.Web.Script.Services;
//返回CascadingDropDownNameValue数组所需的命名空间
using AjaxControlToolkit;
using System.Collections.Generic;
using System.Collections.Specialized;
/**//// <summary>
///WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
public WebService()
{
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public CascadingDropDownNameValue[] GetproviceNames(string knownCategoryValues, string category)
{
List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["Personal"].ConnectionString);
SqlCommand comm = conn.CreateCommand();
comm.CommandText = "select [ProvinceID],[ProvinceName] from [S_Province] order by 1";
conn.Open();
try
{
SqlDataReader dr = comm.ExecuteReader();
while (dr.Read())
{
values.Add(new CascadingDropDownNameValue(dr[1].ToString(), dr[0].ToString()));
}
return values.ToArray();
}
finally
{
conn.Close();
}
}
[WebMethod]
public CascadingDropDownNameValue[] GetCityNames(string knownCategoryValues, string category)
{
StringDictionary kcv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
if (!kcv.ContainsKey("provice"))
{
return null;
}
List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["Personal"].ConnectionString);
SqlCommand comm = conn.CreateCommand();
comm.CommandText = "select [CityID],[CityName] from [S_City] where [ProvinceID]=@ProvinceID order by 1";
comm.Parameters.Add("@ProvinceID", SqlDbType.Int).Value = kcv["provice"];
conn.Open();
try
{
SqlDataReader dr = comm.ExecuteReader();
while (dr.Read())
{
values.Add(new CascadingDropDownNameValue(dr[1].ToString(), dr[0].ToString()));
}
return values.ToArray();
}
finally
{
conn.Close();
}
}
[WebMethod]
public CascadingDropDownNameValue[] GetDistrictNames(string knownCategoryValues, string category)
{
StringDictionary kcv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
if (!kcv.ContainsKey("city"))
{
return null;
}
List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["Personal"].ConnectionString);
SqlCommand comm = conn.CreateCommand();
comm.CommandText = "select [DistrictID],[DistrictName] from [S_District] where [CityID]=@CityID order by 1";
comm.Parameters.Add("@CityID", SqlDbType.Int).Value = kcv["city"];
conn.Open();
try
{
SqlDataReader dr = comm.ExecuteReader();
while (dr.Read())
{
values.Add(new CascadingDropDownNameValue(dr[1].ToString(), dr[0].ToString()));
}
return values.ToArray();
}
finally
{
conn.Close();
}
}
}
数据库脚本下载链接:
http://files.cnblogs.com/dushouke/PCD_AllData_V1.rar
- 全国省市县三级联动(数据完整版)
- 全国省市三级联动
- 全国省市三级联动
- 全国省市县三级地址联动js
- jquery全国省市县三级联动
- 全国省市县三级联动数据库
- 三级联动(省市县)
- 省市县三级联动
- 省市县三级联动
- 省市县三级联动
- 省市县三级联动
- 省市县三级联动
- 省市县三级联动
- 省市县,三级联动。
- 省市县三级联动
- 省市县三级联动
- 省市县三级联动
- 省市县 三级联动
- 用curl命令,post提交带空格的数据
- mysql 读出及写入中文乱码问题与解决
- 文章测试
- IIS出现server application error
- ChinUnix.com的文档手册中心
- 全国省市县三级联动(数据完整版)
- iBATIS sql中的大于、小于、like等符号写法
- S7-PLCSIM仿真操作步骤
- 解决Windows 程序界面闪烁问题的一些经验
- MySQL常用命令及基本操作总结
- 存储某两个年-月之间所有年-月
- WS_CLIPCHILDREN与WS_CLIPSIBLINGS
- 为什么作为学生学习计算机还感觉这么累?
- 浅谈C++中Char、int和flaot在计算机中的表示