使用具有级联下拉菜单的Web服务

时间:2021-11-21 03:13:00

Below is my code -

以下是我的代码 -

 <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 />

In my Page_Load function I have

在我的Page_Load函数中

{
        ddlCategories.DataBind();
}

and my GetCategories Method is

我的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();
    }

But when the page is loaded, the GetCategories function is never called. And my ddlCategories drop down has these items in the list - Please select a category [Method Error 400]

但是当加载页面时,从不调用GetCategories函数。我的ddlCategories下拉列表中有这些项目 - 请选择一个类别[方法错误400]

Is there a step I am missing?

我缺少一步吗?

1 个解决方案

#1


0  

From looking at the CascadingDropDown sample and your code, I think you may have the properties set slightly wrong. Your CascadingDropDown's TargetControlId is currently ddlCategories, however I think this value should be set to the ParentControlId property instead, and you need another DropDownList which becomes the target control of the extender e.g.

从查看CascadingDropDown示例和您的代码,我认为您可能会将属性设置略有错误。你的CascadingDropDown的TargetControlId当前是ddlCategories,但我认为这个值应该设置为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...]" />

#1


0  

From looking at the CascadingDropDown sample and your code, I think you may have the properties set slightly wrong. Your CascadingDropDown's TargetControlId is currently ddlCategories, however I think this value should be set to the ParentControlId property instead, and you need another DropDownList which becomes the target control of the extender e.g.

从查看CascadingDropDown示例和您的代码,我认为您可能会将属性设置略有错误。你的CascadingDropDown的TargetControlId当前是ddlCategories,但我认为这个值应该设置为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...]" />