2011-08-08 15 views
0

Im在這裏發佈了這個問題,導致這個事情實際上在過去的幾周裏破壞了我的頭腦。我離開了它一段時間,但如果可以的話,我真的會使用這個工具。常量錯誤在AjaxToolkit 4.0中使用500級聯DropDown列表ASP.NET

我在下拉列表中一直得到泛型Error 500。

下面是該服務的代碼:

using System; 
using System.Web; 
using System.Collections; 
using System.Collections.Generic; 
using System.Collections.Specialized; 
using System.Web.Services; 
using System.Web.Services.Protocols; 
using AjaxControlToolkit; 
using System.Data; 
using System.Data.SqlClient; 


/// <summary> 
/// Summary description for inputHoursWS 
/// </summary> 
[WebService(Namespace = "http://tempuri.org/")] 
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
// To allow this Web Service to be called from script, using ASP.NET AJAX, 
//uncomment the following line. 
[System.Web.Script.Services.ScriptService] 
public class inputHoursWS : System.Web.Services.WebService { 

    public inputHoursWS() { 

     //Uncomment the following line if using designed components 
     //InitializeComponent(); 
    } 

    [WebMethod] 
    public CascadingDropDownNameValue[] getGroupCodes(string knownCategoryValues, 
    string Category) 
    { 
     InputHoursDSTableAdapters.TMS_ProjectGroupsTableAdapter projectGroupTA = new InputHoursDSTableAdapters.TMS_ProjectGroupsTableAdapter(); 
     InputHoursDS.TMS_ProjectGroupsDataTable groups = projectGroupTA.GetProjectGroups(); 

     List<CascadingDropDownNameValue> groupValues = new List<CascadingDropDownNameValue>(); 

     foreach (DataRow row in groups) 
     { 

      int groupId = (int)row["ProjectGroupID"]; 
      string groupCode = (string)row["ProjectGroup"]; 

      groupValues.Add(new CascadingDropDownNameValue(groupCode, groupId.ToString())); 

     } 

     return groupValues.ToArray(); 
    } 

} 

下面是前端Web表單代碼:

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 

        <asp:DropDownList ID="ddlGroups" runat="server" Width="70px" Height="21px"> 
        </asp:DropDownList> 
        <asp:CascadingDropDown ID="ddlGroups_CascadingDropDown" 
         runat="server" 
         TargetControlID="ddlGroups" 
         Category="ProjectGroup" 
         PromptText="Choose a Group" 
         LoadingText="Please wait ..." 
         ServicePath="inputHoursWS.asmx" 
         ServiceMethod="getGroupCodes"> 
         </asp:CascadingDropDown> 

在InputHoursDS數據集的方法是否工作正常。我正在遠程訪問正在開發的機器。有一個的Visual Web Developer 2010安裝,也是IIS 6中運行.NET 4.0

而且一個簡單的問題也有關係 - 你把什麼樣的價值,在「類別」屬性在前端?是數據庫標題還是其自己的標題?

回答

0

好吧, 我想我沒有意識到的是,數據集沒有正確設置,實際上在另一種方法我混淆了方法名稱。

使用調試工具,如Fiddler。它真的幫助了我。

回答我自己的問題。我的理解是,該類別是下一個下拉列表的主鍵列,而knownCategoryValues是前一個鍵的值。這裏的實際工作一塊吧,這樣大家尋找一個答案可以使用它:

[WebMethod] 
    public CascadingDropDownNameValue[] getGroups(string knownCategoryValues, string category) 
    { 
    StringDictionary categoryValues = 
AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(
knownCategoryValues); 

    int countryID = Convert.ToInt32(categoryValues["ProjectGroupID"]); 

    List<CascadingDropDownNameValue> cascadingValues = 
     new List<CascadingDropDownNameValue>(); 

    inputHrsDataSetTableAdapters.TMS_ProjectGroupsTableAdapter projectGroupsTA = new inputHrsDataSetTableAdapters.TMS_ProjectGroupsTableAdapter(); 


    foreach (DataRow _row in projectGroupsTA.GetProjectGroupCodes()) 
    { 
     cascadingValues.Add(new CascadingDropDownNameValue(_row["ProjectGroup"].ToString(), 
      _row["ProjectGroupID"].ToString())); 

    } 

    return cascadingValues.ToArray(); 
} 

    [WebMethod] 
    public CascadingDropDownNameValue[] getProjectNumbers(string knownCategoryValues, string category) 
{ 
    StringDictionary categoryValues = 
AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(
knownCategoryValues); 

    int GroupaID = Convert.ToInt32(categoryValues["ProjectGroupID"]); 

    List<CascadingDropDownNameValue> cascadingValues = 
     new List<CascadingDropDownNameValue>(); 

    inputHrsDataSetTableAdapters.TMS_ProjectRegisterTableAdapter projectRegisterTA = new inputHrsDataSetTableAdapters.TMS_ProjectRegisterTableAdapter(); 


    foreach (DataRow _row in projectRegisterTA.GetProjectNumbersFromGroupID(GroupaID)) 
    { 
     cascadingValues.Add(new CascadingDropDownNameValue(_row["ProjectNumber"].ToString(), 
      _row["ProjectNumber"].ToString())); 

    } 

    return cascadingValues.ToArray(); 

} 

也:

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 

            <asp:DropDownList ID="ddlGroupCodes" runat="server" Height="21px" Width="70px" /> 

            <asp:CascadingDropDown ID="ddlGroupCodes_CascadingDropDown" runat="server" 
             TargetControlID="ddlGroupCodes" 
             Category="ProjectGroupID" 
             ServicePath="~/GroupService.asmx" 
             ServiceMethod="getGroups" 
             PromptText="Select Group" 
             LoadingText="Loading..."> 
            </asp:CascadingDropDown> 

            <asp:DropDownList ID="ddlProjectNumbers" runat="server" Height="21px" Width="85px" /> 

            <asp:CascadingDropDown ID="ddlProjectNumbers_CascadingDropDown" runat="server" 
             TargetControlID="ddlProjectNumbers" 
             Category="ProjectNumber" 
             ServicePath="~/GroupService.asmx" 
             ServiceMethod="getProjectNumbers" 
             PromptText="Select Project No." 
             LoadingText="Loading..." ParentControlID="ddlGroupCodes"> 
            </asp:CascadingDropDown> 

得到所有的好聽感謝提琴手!真的,用它進行調試,它很棒。

再次使用調試工具!!!你不想花費一輩子的方法簡單的拼寫錯誤:)。

2

對我來說,加入下面的配置,以我的web.config文件解決了這個問題:

<configuration> 

    <!-- ... --> 

    <system.web.extensions> 
    <scripting> 
     <webServices> 
     <jsonSerialization maxJsonLength="2147483647"/> 
     </webServices> 
    </scripting> 
    </system.web.extensions> 

    <!-- ... --> 

</configuration> 

我一直看到的問題在下拉菜單,其中列出可用於某個特定國家的城市。大多數國家我們只有幾個城市的定義,但一個是有成千上萬的城市;這只是那個錯誤的國家;儘管在調試代碼時看起來很好(因爲調用的方法正在運行並返回結果 - 結果只是大於可接受的大小。修改最大JSON長度消除了這個人爲問題。