Asp.net 使用具有级联下拉列表的web服务

Asp.net 使用具有级联下拉列表的web服务,asp.net,ajax,Asp.net,Ajax,以下是我的密码- <asp:DropDownList ID="ddlCategories" runat="server" /> <asp:CascadingDropDown ID="cddCategory" runat="server" ServicePath="~\Categories.asmx" ServiceMethod="GetCategories" TargetControlID="ddlCategories" Category="Category" Prom

以下是我的密码-

 <asp:DropDownList ID="ddlCategories" runat="server" />
 <asp:CascadingDropDown ID="cddCategory" runat="server" ServicePath="~\Categories.asmx"
 ServiceMethod="GetCategories" TargetControlID="ddlCategories" Category="Category"
 PromptText="Please select a category" LoadingText="[Loading categories...]" />
 <br />
我的GetCategories方法是

    [WebMethod]
    public CascadingDropDownNameValue[] GetCategories(
      string knownCategoryValues,
      string category)
    {
        List<CascadingDropDownNameValue> l = new List<CascadingDropDownNameValue>();
        l.Add(new CascadingDropDownNameValue("International", "1"));
        l.Add(new CascadingDropDownNameValue("Electronic Bike Repairs & Supplies", "2"));
        l.Add(new CascadingDropDownNameValue("Premier Sport, Inc.", "3"));
        return l.ToArray();
    }
但是当加载页面时,永远不会调用GetCategories函数。“我的类别”下拉列表中有这些项目- 请选择一个类别 [方法错误400]


是否有我遗漏的步骤?

从查看CascadingDropDown和您的代码来看,我认为您的属性设置可能有点错误。您的CascadingDropDown的TargetControlId当前为DDLComplements,但是我认为应该将此值设置为ParentControlId属性,并且您需要另一个DropDownList,它将成为扩展器的目标控件,例如

<asp:DropDownList ID="ddlCategories" runat="server" /><br/>
<asp:DropDownList id="ddlSubcategories" runat="server" />
<asp:CascadingDropDown ID="cddCategory" TargetControlID="ddlSubcategories" ParentControlId="ddlCategories" runat="server" ServicePath="~\Categories.asmx" 
ServiceMethod="GetCategories" Category="Category"  
PromptText="Please select a category" LoadingText="[Loading categories...]" />

Phil,这里是TargetControlId的定义-•TargetControlId-要填充的DropDownList的ID。其他想法?@duckmike你对CascadingDropDown的理解是什么?我的观点是,您有两个或多个下拉列表,其中CascadingDropDown extender应用于第二个和后续的下拉列表,因此,当您在第一个下拉列表中选择一个项目时,extender会截取该选择,并在下一个下拉列表中将列表过滤为任何合适的值集。因此,您需要两个dropdownlists,其中扩展器应用于第二个dropdownlists。谢谢,这非常有用。
<asp:DropDownList ID="ddlCategories" runat="server" /><br/>
<asp:DropDownList id="ddlSubcategories" runat="server" />
<asp:CascadingDropDown ID="cddCategory" TargetControlID="ddlSubcategories" ParentControlId="ddlCategories" runat="server" ServicePath="~\Categories.asmx" 
ServiceMethod="GetCategories" Category="Category"  
PromptText="Please select a category" LoadingText="[Loading categories...]" />