Click here to Skip to main content
15,065,758 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using 2 dropdown lists in parent child relationship and are present inside one update panel but when even i select some data from parent dropdown list, insted of filling the second dropdown list it just creates duplicate dropdown lists for both the dopdown list making 4 dropdownlists on the page.

My code is

SQL
<asp:UpdatePanel ID="up1" runat="server" UpdateMode="Always">
<ContentTemplate>
          <td valign="top">
                                                        <asp:DropDownList ID="ddlProject" runat="server" Width="105" AutoPostBack="true"
                                                            OnSelectedIndexChanged="ddlProject_SelectedIndexChanged">
                                                        </asp:DropDownList>
                                                    </td>
                                                    <td valign="top">
                                                        <asp:DropDownList ID="ddlSubProject" runat="server" Width="105" AutoPostBack="true"
                                                            OnSelectedIndexChanged="ddlSubProject_SelectedIndexChanged">
                                                        </asp:DropDownList>
                                                    </td>
                                                
</ContentTemplate>
 <Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlProject" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>




Code is as folows


C#
protected void ddlProject_SelectedIndexChanged(object sender, EventArgs e)
   {
       ClsCommon.FillDropDown(ddlSubProject, BALProjectUseCases.GetAllSubProjectByProject(Convert.ToInt32(ddlProject.SelectedValue)), DropDownSelectText, "FieldName", "id");

}

C#
protected void ddlSubProject_SelectedIndexChanged(object sender, EventArgs e)
   {
       ClsCommon.FillDropDown(ddlUseCase, BALProjectUseCases.GetAllUseCasesByProject(Convert.ToInt32(ddlSubProject.SelectedValue)), DropDownSelectText, "FieldName", "id");
   }




C#
public static void FillDropDown<T>(DropDownList ddlList, List<T> oList, string strSelectText, string strDataTextField, string strDataValueField) where T : class
   {
       try
       {
           if (oList.Count > 0)
           {
               ddlList.Items.Clear();
               ddlList.DataSource = oList;
               ddlList.DataTextField = strDataTextField;
               ddlList.DataValueField = strDataValueField;
               ddlList.DataBind();
               if (strSelectText != "")
                   ddlList.Items.Insert(0, new ListItem(strSelectText, "0"));
           }
           else
           {
               ddlList.Items.Clear();
               ddlList.Items.Insert(0, new ListItem(strSelectText, "0"));
           }

       }
Posted
Updated 28-May-15 2:21am
v3
Comments
Richard Deeming 28-May-15 7:42am
   
There's something wrong with the code which fills the lists. Since you haven't shown that code, we can't tell you what the problem is.

Use the "Improve solution" link to update your question with the missing code.

1 solution

please check page load event
and delete Triggers tag
   
Comments
Vinay1337 28-May-15 9:01am
   
but without trigger it goes for full page post back.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900