在 Ajax 控制工具包中的级联下拉列表更新中

发布于 2024-08-29 07:46:50 字数 2546 浏览 2 评论 0原文

当我使用级联下拉菜单时,我收到 [MethodError 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"/>

服务代码:

 [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;
    }

}

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));
        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;
    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷月断魂刀 2024-09-05 07:46:50

在 webMethods 中添加一些带有异常日志记录的 try catch 块怎么样?

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

情深如许 2024-09-05 07:46:50

我将 [ScriptService] 属性保留在服务类之上,现在它正在工作。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文