2013-03-12 63 views
0

我有2个级联下拉菜单,1是父级,一旦您在第一个/父级下拉菜单中选择一个值,则会填充其他/子级。根据父值设置选定值

第一个在页面加载时填充,我可以根据上一页保存的数据库值为此设置选定的值。

对于第二个级联下拉菜单,当我在页面加载时(基于数据库值)设置父级ID的选定值时,它会为我填充。

但是由于第二个/下拉菜单没有设置/加载值直到页面加载,我无法设置选定的值(我在Page_Load_Complete上尝试过,但它在那里也不起作用)。

我需要知道如何在父级下拉菜单中设置所选值(此工作正常),以基于第一个下拉菜单中的值填充第二个下拉菜单。

这是我的aspx页面的代码。我可以设置所选的第一个值,它填充第二个选择框(但我不能设置所选择的价值,因为它不是在我设定的第一个选定值的时间填充。

aspx页面

<asp:Label ID="lblAffPartCat" Text="<%$ Resources:share,lblAffPartCat %>" runat="server"></asp:Label> 
<asp:DropDownList ID="ddlPartCat" runat="server"></asp:DropDownList> 

<ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server" TargetControlID="ddlPartCat" 
Category="BasePart" PromptText="<%$ Resources:share,lblSelPartCat %>" LoadingText="[Loading Part Cat...]" 
ServicePath="PAIntExtPart.asmx" ServiceMethod="BindPartCat" 
ContextKey="" UseContextKey="True"/> 

<asp:Label ID="lblAffBasePart" Text="<%$ Resources:share,lblAffBasePart %>" runat="server"></asp:Label> 

<asp:DropDownList ID="ddlBasePart" runat="server" ></asp:DropDownList> 

<ajaxToolkit:CascadingDropDown ID="ddlBasePart_CascadingDropDown" runat="server" Category="BasePart" 
TargetControlID="ddlBasePart" ParentControlID= "ddlPartCat" PromptText="<%$ Resources:share,lblSelBasePart %>" 
LoadingText="Loading Base Parts.." 
ServicePath="PAIntExtPart.asmx" 
ServiceMethod="BindBasePart" 
ContextKey="" UseContextKey="True" /> 

asmx.cs页面填充下拉列表:

using System; 
using System.Collections.Generic; 
using System.Web.Services; 
using System.Data; 
using System.Collections.Specialized; 
using AjaxControlToolkit; 
using Hotline.DataAccess; 

/// <summary> 
    /// Summary description for PAIntExtPart 
    /// </summary> 
    [WebService(Namespace = "http://tempuri.org/")] 
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
    [System.ComponentModel.ToolboxItem(false)] 
    // 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 PAIntExtPart : System.Web.Services.WebService 
    { 
     string _SiteLocation = MiscFunctions.getCurrentSiteLocation(); 

     /// <summary> 
     /// WebMethod to Populate Part Category Dropdown 
     /// </summary> 
     [WebMethod] 
     public CascadingDropDownNameValue[] BindPartCat(string knownCategoryValues, string category, string contextKey) 
     { 
      DataTable dsPartCat = null; 

      // string passed for contextKey is FormType and Language split by ":" 
      string[] arrcontextKey = contextKey.Split(':'); 

      string FormType = arrcontextKey[0].ToString(); 
      int LanguageID = Int32.Parse(arrcontextKey[1].ToString()); 
      string PartCatValue = arrcontextKey[2].ToString(); 

      try 
      {     
       dsPartCat = HarDB.getPartCat(_SiteLocation, LanguageID, FormType); 

       //create list and add items in it by looping through dataset table 
       List<CascadingDropDownNameValue> PartCatdetails = new List<CascadingDropDownNameValue>(); 
       foreach (DataRow dtrow in dsPartCat.Rows) 
       { 
        string PartCatID = dtrow["PartCatID"].ToString(); 
        string PartCat = dtrow["PartCat"].ToString(); 
        PartCatdetails.Add(new CascadingDropDownNameValue(PartCat, PartCatID)); 

       } 

       if (PartCatValue.Trim() != "") 
       {      
        //SelectedValue = PartCatValue; 
       } 

       return PartCatdetails.ToArray(); 

      } 
      catch (Exception ex) 
      { 
       Server.Transfer("Errorpage.aspx?function=getAttachInfo+Error=" + Server.UrlEncode(ex.Message)); 
       return null; 
      } 

     } 

     /// <summary> 
     /// WebMethod to Populate Base Part Dropdown 
     /// </summary> 
     [WebMethod] 
     public CascadingDropDownNameValue[] BindBasePart(string knownCategoryValues, string category, string contextKey) 
     { 
      string PartCatID; 
      //int LanguageID = Int32.Parse(contextKey); 

      string[] arrcontextKey = contextKey.Split(':'); 

      string FormType = arrcontextKey[0].ToString(); 
      int LanguageID = Int32.Parse(arrcontextKey[1].ToString()); 
      string BasePartValue = arrcontextKey[2].ToString(); 

      //This method will return a StringDictionary containing the name/value pairs of the currently selected values 
      StringDictionary PartCatdetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); 

      PartCatID = PartCatdetails["BasePart"]; 


      DataTable dsBasePart = null; 
      try 
      { 
       dsBasePart = HarDB.getBasePart(_SiteLocation, LanguageID, PartCatID, FormType); 

       //create list and add items in it by looping through dataset table 
       List<CascadingDropDownNameValue> BasePartdetails = new List<CascadingDropDownNameValue>(); 
       foreach (DataRow dtrow in dsBasePart.Rows) 
       { 
        string BasePartID = dtrow["BasePartNumID"].ToString(); 
        string BasePart = dtrow["BasePartNum"].ToString(); 
        BasePartdetails.Add(new CascadingDropDownNameValue(BasePart, BasePartID)); 
       } 

       if (BasePartValue.Trim() != "") 
       { 
        //SelectedValue = PartCatValue; 
       } 

       return BasePartdetails.ToArray(); 

      } 
      catch (Exception ex) 
      { 
       Server.Transfer("Errorpage.aspx?function=getAttachInfo+Error=" + Server.UrlEncode(ex.Message)); 
       return null; 
      } 

     } 

    } 
+0

我已经编辑你的ti TLE。请参阅:“[应该在其标题中包含”标签“](http://meta.stackexchange.com/questions/19190/)”,其中的共识是“不,他们不应该”。 – 2013-03-13 18:22:33

回答

0

我发现我的问题,我想填充第二个下拉时未使用正确的“选定值”