<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CascadingDropDown.aspx.cs" Inherits="AjaxToolkit.CascadingDropDown" 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>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList3" runat="server">
</asp:DropDownList>
<asp:Label ID="Label1" runat="server"></asp:Label>
<cc1:CascadingDropDown ID="CascadingDropDown1" runat="server"
Category="province" LoadingText="[loading a province]" ServicePath="CityService.asmx"
PromptText="please select a province" ServiceMethod="GetDropDownContents"
TargetControlID="DropDownList1">
</cc1:CascadingDropDown>
<cc1:CascadingDropDown ID="CascadingDropDown2" runat="server" Category="city"
LoadingText="[loading a city]" ParentControlID="DropDownList1" ServicePath="CityService.asmx"
PromptText="please select a city" ServiceMethod="GetDropDownContents"
TargetControlID="DropDownList2">
</cc1:CascadingDropDown>
<cc1:CascadingDropDown ID="CascadingDropDown3" runat="server" Category="town"
LoadingText="[loading a town]" PromptText="please select a towm" ParentControlID="DropDownList2" ServicePath="CityService.asmx"
ServiceMethod="GetDropDownContents" TargetControlID="DropDownList3">
</cc1:CascadingDropDown>
<asp:Button ID="Button1" runat="server" οnclick="Button1_Click" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
========webservice========
[System.Web.Script.Services.ScriptService]
public class CityService : System.Web.Services.WebService
{
public System.Xml.XmlDocument _document;
public object _lock;
public System.Xml.XmlDocument Document
{
get
{
_document = new System.Xml.XmlDocument();
_document.Load(HttpContext.Current.Server.MapPath("~/App_Data/Data.xml"));
return _document;
}
}
public string[] Hierachy
{
get
{
string[] _hierachy = new string[]{"province","city","town" };
return _hierachy;
}
}
[WebMethod]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownContents(string knownCategoryValues, string category)
{
System.Collections.Specialized.StringDictionary knowCategoryValuesDictionary = new System.Collections.Specialized.StringDictionary();
knowCategoryValuesDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
return AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document,Hierachy,knowCategoryValuesDictionary,category);
}
}
=====XML========
<?xml version="1.0" encoding="utf-8" ?>
<country>
<province name="guangdong" value="guangdong">
<city name="guangzhou" value="guangzhou">
<town name="huadu" value="huadu"></town>
<town name="haizhu"></town>
<town name="xiguan"></town>
</city>
<city name="foshan">
<town name="chancheng"></town>
<town name="shunde"></town>
<town name="nanhai"></town>
</city>
<city name="shenzhen">
<town name="longgang"></town>
<town name="bantian"></town>
<town name="luohu"></town>
</city>
</province>
</country>