开发者

in Cascading dropdown update in Ajax Control Toolkit

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

    <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));
  开发者_如何学C      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;
    }

}


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜