在Ajax控件工具包中的级联下拉更新

时间:2022-11-06 19:03:08

I am getting [MethodError 500] when I use cascading drop down. below is my code

当我使用级联下降时,我得到[方法500]。下面是我的代码

    <tr>
<td >
Select a Hoster: 
</td>
<td>
<asp:DropDownList ID="ddlFeaturedHoster" runat="server" ></asp:DropDownList>
 </td>
 </tr>


<ajaxToolkit:CascadingDropDown ID="cddHoster" runat="server" TargetControlID="ddlFeaturedHoster"
                             PromptText="Select a Hoster" LoadingText="Loading ..." Category="ActiveHoster"
                            ServiceMethod="GetDropDownContents" ServicePath="~/Hosting/HostingService.asmx"/>

Service Code:

服务代码:

 [WebMethod]
    [ScriptMethod]
    public CascadingDropDownNameValue[] GetActiveHosters()
    {

        List<CascadingDropDownNameValue> returnList = new List<CascadingDropDownNameValue>();
        HostersManager hosterManager = new HostersManager();
        List<Hosters_HostingProviderDetail> hosters = hosterManager.GetAllHosters();
        returnList.Add(new CascadingDropDownNameValue("--Please Select One--","0",true));
        foreach (Hosters_HostingProviderDetail item in hosters)
        {
            returnList.Add(new CascadingDropDownNameValue() {  name=item.HostingProviderName, value= item.HosterID.ToString()});
        }
        return returnList.ToArray() ;
    }
  [WebMethod]
    [ScriptMethod]
    public CascadingDropDownNameValue[] GetDropDownContents(string knownCategoryValues, string category)
    {
        knownCategoryValues = FormatCategoryWord(knownCategoryValues);
        List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
        HostersManager hosterManager = new HostersManager();
        switch (category)
        {
            case "ActiveHoster":
                values.AddRange(GetActiveHosters());
                break;
            case "ActiveOffer":
                values.AddRange(GetActiveOffers(1));
                break;
        }
        return values.ToArray<CascadingDropDownNameValue>();

    }

    /// <summary>
    /// Formats the category word
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    private string FormatCategoryWord(string value)
    {
        if (string.IsNullOrEmpty(value)) return value;
        if (value.LastIndexOf(":") > 0) value = value.Substring(value.LastIndexOf(":") + 1);
        if (value.LastIndexOf(";") > 0) value = value.Substring(0, value.LastIndexOf(";"));
        return value;
    }

}

2 个解决方案

#1


3  

How about some try catch blocks within your webMethods with some exception logging?

在webMethods中使用异常日志记录尝试捕获块怎么样?

#2


0  

I kept [ScriptService] attribute on top of service class its working now.

我将[ScriptService]属性保存在服务类的顶部,现在它可以工作了。

#1


3  

How about some try catch blocks within your webMethods with some exception logging?

在webMethods中使用异常日志记录尝试捕获块怎么样?

#2


0  

I kept [ScriptService] attribute on top of service class its working now.

我将[ScriptService]属性保存在服务类的顶部,现在它可以工作了。