2013-03-12 5 views
0

J'ai 2 listes déroulantes en cascade, 1 est un parent et l'autre/enfant remplit une fois que vous sélectionnez une valeur dans le premier/parent déroulant.Définir la valeur sélectionnée basée sur la valeur parente

La première se charge au chargement de la page et je peux définir la valeur sélectionnée pour celle-ci en fonction de la valeur de la base de données qui a été enregistrée sur la page précédente.

Pour la deuxième liste déroulante en cascade, elle se remplit pour moi lorsque je définis la valeur sélectionnée pour l'ID parent lors du chargement de la page (en fonction de la valeur de la base de données). Mais comme le menu déroulant second/child n'est pas défini/chargé avec des valeurs jusqu'à ce que la page se charge, je ne peux pas définir la valeur sélectionnée (j'ai essayé sur Page_Load_Complete mais cela ne fonctionne pas non plus).

J'ai besoin de savoir comment, une fois que j'ai défini la valeur sélectionnée dans la liste déroulante parente (cela fonctionne bien), pour remplir la deuxième liste déroulante basée sur la valeur dans le premier.

Voici mon code pour la page aspx. Je peux définir la première valeur sélectionnée, et il remplit la deuxième boîte de sélection (mais je ne peux pas définir la valeur choisie parce qu'elle est pas remplie au moment où je mets la première valeur sélectionnée.

page 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 page qui renseigne les bas de baisse.

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

J'ai modifié ton ti tle. S'il vous plaît voir, "[Les questions devraient inclure" tags "dans leurs titres?] (Http://meta.stackexchange.com/questions/19190/)", où le consensus est "non, ils ne devraient pas". –

Répondre

0

je trouve ma question, je n'utilisais pas la bonne « valeur sélectionnée » lorsque vous essayez de remplir la deuxième liste déroulante

Questions connexes