<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Confirm.aspx.cs" Inherits="admin_Confirm" %><%@ 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>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</cc1:ToolkitScriptManager>
<cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" runat="server" TargetControlID="DropDownList1" ServiceMethod="GetProvince" ServicePath="~/CityService.asmx" Category="Province" LoadingText="loading.." PromptText="选择省">
</cc1:CascadingDropDown>
<cc1:CascadingDropDown ID="CascadingDropDown2" runat="server" runat="server" TargetControlID="DropDownList2" ServiceMethod="GetCity" ServicePath="~/CityService.asmx" Category="City" LoadingText="loading.." PromptText="选择市">
</cc1:CascadingDropDown>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Collections.Specialized;
using AjaxControlToolkit;
using System.Data;/// <summary>
///CityService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
public class CityService : System.Web.Services.WebService { public CityService () { //如果使用设计的组件,请取消注释以下行
//InitializeComponent();
} [WebMethod]
[System.Web.Script.Services.ScriptMethod()]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetProvince(string knownCategoryValues, string category)
{
List<AjaxControlToolkit.CascadingDropDownNameValue> ListData = new List<AjaxControlToolkit.CascadingDropDownNameValue>();
DataSet ds = DBHelper.Query("select * from area");
if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0) return null;
foreach (DataRow row in ds.Tables[0].Rows)
{
if (row["parentcode"].ToString() == "0")
{
AjaxControlToolkit.CascadingDropDownNameValue value = new AjaxControlToolkit.CascadingDropDownNameValue();
value.name = row["name"].ToString();
value.value = row["sz_code"].ToString();
ListData.Add(value);
}
}
return ListData.ToArray();
} [WebMethod]
[System.Web.Script.Services.ScriptMethod()]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetCity(string knownCategoryValues, string category)
{
StringDictionary sd = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
if (sd == null) return null;
if (sd.ContainsKey("Province") == false) return null;
int parentID = Int32.Parse(sd["Province"]);
DataSet ds =DBHelper.Query("select * from area");
if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0) return null;
List<AjaxControlToolkit.CascadingDropDownNameValue> ListData = new List<CascadingDropDownNameValue>();
foreach (DataRow row in ds.Tables[0].Rows)
{
if (row["ParentCode"].ToString() == parentID.ToString())
{
AjaxControlToolkit.CascadingDropDownNameValue value = new AjaxControlToolkit.CascadingDropDownNameValue();
value.name = row["name"].ToString();
value.value = row["sz_code"].ToString();
ListData.Add(value);
}
}
return ListData.ToArray();
}
}
不太明白为什么结果是这样
省能出现,但城市却不能选择,只处于不可选状态。
数据库是由 parentcode 为0 的话 就得出 省的Name ,
然后市那里就根据选出的省,得出市
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</cc1:ToolkitScriptManager>
<cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" runat="server" TargetControlID="DropDownList1" ServiceMethod="GetProvince" ServicePath="~/CityService.asmx" Category="Province" LoadingText="loading.." PromptText="选择省">
</cc1:CascadingDropDown>
<cc1:CascadingDropDown ID="CascadingDropDown2" runat="server" runat="server" TargetControlID="DropDownList2" ServiceMethod="GetCity" ServicePath="~/CityService.asmx" Category="City" LoadingText="loading.." PromptText="选择市">
</cc1:CascadingDropDown>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Collections.Specialized;
using AjaxControlToolkit;
using System.Data;/// <summary>
///CityService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
public class CityService : System.Web.Services.WebService { public CityService () { //如果使用设计的组件,请取消注释以下行
//InitializeComponent();
} [WebMethod]
[System.Web.Script.Services.ScriptMethod()]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetProvince(string knownCategoryValues, string category)
{
List<AjaxControlToolkit.CascadingDropDownNameValue> ListData = new List<AjaxControlToolkit.CascadingDropDownNameValue>();
DataSet ds = DBHelper.Query("select * from area");
if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0) return null;
foreach (DataRow row in ds.Tables[0].Rows)
{
if (row["parentcode"].ToString() == "0")
{
AjaxControlToolkit.CascadingDropDownNameValue value = new AjaxControlToolkit.CascadingDropDownNameValue();
value.name = row["name"].ToString();
value.value = row["sz_code"].ToString();
ListData.Add(value);
}
}
return ListData.ToArray();
} [WebMethod]
[System.Web.Script.Services.ScriptMethod()]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetCity(string knownCategoryValues, string category)
{
StringDictionary sd = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
if (sd == null) return null;
if (sd.ContainsKey("Province") == false) return null;
int parentID = Int32.Parse(sd["Province"]);
DataSet ds =DBHelper.Query("select * from area");
if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0) return null;
List<AjaxControlToolkit.CascadingDropDownNameValue> ListData = new List<CascadingDropDownNameValue>();
foreach (DataRow row in ds.Tables[0].Rows)
{
if (row["ParentCode"].ToString() == parentID.ToString())
{
AjaxControlToolkit.CascadingDropDownNameValue value = new AjaxControlToolkit.CascadingDropDownNameValue();
value.name = row["name"].ToString();
value.value = row["sz_code"].ToString();
ListData.Add(value);
}
}
return ListData.ToArray();
}
}
不太明白为什么结果是这样
省能出现,但城市却不能选择,只处于不可选状态。
数据库是由 parentcode 为0 的话 就得出 省的Name ,
然后市那里就根据选出的省,得出市
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货