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

设计页面:            

 <asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
            <asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList>
            <asp:DropDownList ID="DropDownList3" runat="server" OnSelectedIndexChanged="DropDownList3_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>


            <ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" Category="type" //注意这个type
            PromptText="请选择你要查看的类别"
            ServicePath ="CascadingDropDownDemo.asmx" //获取源数据的服务方法路径
            ServiceMethod="GetDropDownContents" //这个是方法,在上面那个文件
            TargetControlID="DropDownList1" runat="server">
            </ajaxToolkit:CascadingDropDown>
           
           
            <ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" Category="name"
            PromptText="请选择你要查看的名称"
            ServicePath="CascadingDropDownDemo.asmx"            

ServiceMethod="GetDropDownContents"      

TargetControlID="DropDownList2"
            ParentControlID="DropDownList1"  runat="server">
            </ajaxToolkit:CascadingDropDown>
            <ajaxToolkit:CascadingDropDown ID="CascadingDropDown3" Category="info"
            PromptText="请选择你要查看的信息"
            ServicePath="CascadingDropDownDemo.asmx"
            ServiceMethod="GetDropDownContents"
            TargetControlID="DropDownList3"
            ParentControlID="DropDownList2" runat="server">
            </ajaxToolkit:CascadingDropDown>

 

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;
/// <summary>
/// CascadingDropDownDemo 的摘要说明
/// </summary>
[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);
    }

 

 

   
}

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值