基于asp.net的Ajax 级联下拉菜单

设计页面:            

 
           
           


                        PromptText="请选择你要查看的类别"
            ServicePath ="CascadingDropDownDemo.asmx" //获取源数据的服务方法路径
            ServiceMethod="GetDropDownContents" //这个是方法,在上面那个文件
            TargetControlID="DropDownList1" runat="server">
           

           
           
                        PromptText="请选择你要查看的名称"
            ServicePath="CascadingDropDownDemo.asmx"            

ServiceMethod="GetDropDownContents"      

TargetControlID="DropDownList2"
            ParentControlID="DropDownList1"  runat="server">
           
                        PromptText="请选择你要查看的信息"
            ServicePath="CascadingDropDownDemo.asmx"
            ServiceMethod="GetDropDownContents"
            TargetControlID="DropDownList3"
            ParentControlID="DropDownList2" runat="server">
           

 

CascadingDropDownDemo.asmx文件(是要重新建一个web服务文件)

这个实例是读取xml文件的

using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;
using System.Collections.Specialized;
using System.Web.Script.Services;
///


/// CascadingDropDownDemo 的摘要说明
///

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]


[ScriptService]//这个添加,最后那个命名空间


public class CascadingDropDownDemo : System.Web.Services.WebService {

    public CascadingDropDownDemo () {

        //如果使用设计的组件,请取消注释以下行
        //InitializeComponent();
    }

    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }

    private static XmlDocument _document;
    private static object _lock = new object();

    public static XmlDocument Document
    {
        get
        {
            lock (_lock)
            {
                if (_document == null)
                {
                    _document = new XmlDocument();
                    _document.Load(HttpContext.Current.Server.MapPath("~/App_Data/CascadingDropDownDemo.xml"));
                }
            }
            return _document;
        }
    }

    public static string[] Hierarchy
    {
        get { return new string[] { "type", "name" }; }
    }

    //获取得列表数据
    [WebMethod]
    public AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownContents(string knownCategoryValues, string category)
    {
        StringDictionary knownCategoryValuesDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        return AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document, Hierarchy, knownCategoryValuesDictionary, category);
    }

 

 

   
}

 

 

你可能感兴趣的:(asp.net)