Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Hi Dears

I have 3 dropdown lists inside an Update Panel.
Country,State,Area respectively. These 3 Dropdowns are related.

If I choose a Country Name from the Country dropdown then all the states of selected country will be available in state dropdown . It works fine for first postback only...
the state dropdown is not refreshing for all postback except the first postback..

I have used
ASP.NET
<Triggers>
           <asp:AsyncPostBackTrigger ControlID="ddlCountry"  EventName="SelectedIndexChanged"/>
<asp:AsyncPostBackTrigger ControlID="ddlState"  EventName="SelectedIndexChanged"/>
<asp:AsyncPostBackTrigger ControlID="ddlArea"  EventName="SelectedIndexChanged"/></Triggers>


Still not refreshing the state dropdown from the second postback..
Please help me if anyone has Idea about this...

Thanks in advance... :)
Posted
v2

Don't make this complicated. There is a very easy way of doing this using Ajax CascadingDropDown.

Refer - AJAX Cascading DropDown Example in ASP.Net[^]
 
Share this answer
 
Comments
SubhashRokzzz 25-Feb-15 2:58am    
Thank You for your help.. But I have no rights to change the present controls and logics used on the page.Could you please help me to solve this issue ? If I remove the update panel the dropdowns work fine..
Did you debug and see what is happening?
Hi,
Instead of using a single updatepanel use updatepanel with every dropdown, think so it will work fine.
 
Share this answer
 
Try using Single Update Panel....



DESIGNER:

XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Learn How Add ASP.NET 3.5 AJAX UpdatePanel Triggers</title></head>
<body>
    <form id="form1" runat="server">
<div>



    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <br />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Label ID="Label1" runat="server" Text="Country"></asp:Label>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
                onselectedindexchanged="DropDownList1_SelectedIndexChanged">
            </asp:DropDownList>
            <br />
            <asp:Label ID="Label2" runat="server" Text="State"></asp:Label>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"
                Enabled="False" onselectedindexchanged="DropDownList2_SelectedIndexChanged">
            </asp:DropDownList>
            <br />
            <asp:Label ID="Label3" runat="server" Text="City"></asp:Label>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="True"
                Enabled="False" onselectedindexchanged="DropDownList3_SelectedIndexChanged">
            </asp:DropDownList>

            <br />
            <asp:Label ID="Label4" runat="server"></asp:Label>
            <br />
            <br />
        </ContentTemplate>

    </asp:UpdatePanel>



</div>


    </form>


    </body>
</html>




CODE BEHIND:

public partial class _Default : System.Web.UI.Page 
{
protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        List<string> l1 = new List<string>();
        l1.Add("    ");
        l1.Add("India");
        l1.Add("USA");


        foreach (string item in l1)
        {
            DropDownList1.Items.Add(item);
        }
    }
}


protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    DropDownList2.Enabled = true;
    DropDownList3.Enabled = false;
    Label4.Text = "";
    List<string> l2 = new List<string>();
 
    if (DropDownList1.SelectedItem.Text == "India")
    {
            DropDownList2.Items.Clear();
             l2.Add(" ");
             l2.Add("Maharashtra");
             l2.Add("Goa");
           
       
        foreach (string item in l2)
        {
            DropDownList2.Items.Add(item);
        }
    }

    else
    {
        DropDownList2.Items.Clear();
            l2.Add(" ");
            l2.Add("Indiana");
            l2.Add("Texas");
        

        foreach (string item in l2)
        {
            DropDownList2.Items.Add(item);
        }
    }


}


protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
    DropDownList3.Enabled = true;
    List<string> l3 = new List<string>();
   
    if (DropDownList2.SelectedItem.Text == "Maharashtra")
    {
        DropDownList3.Items.Clear();
        l3.Add(" ");
        l3.Add("Pune");
        l3.Add("Mumbai");


        foreach (string item in l3)
        {
            DropDownList3.Items.Add(item);
        }
    }

    else if (DropDownList2.SelectedItem.Text == "Goa")
    {

        DropDownList3.Items.Clear();
            l3.Add(" ");
            l3.Add("Panji");
            l3.Add("Vasco");
    

        foreach (string item   in l3)
        {
            DropDownList3.Items.Add(item);
        }
    }

    else if (DropDownList2.SelectedItem.Text == "Indiana")
    {

        DropDownList3.Items.Clear();
        l3.Add(" ");
        l3.Add("Wilkinson");
        l3.Add("Morocco");


        foreach (string item in l3)
        {
            DropDownList3.Items.Add(item);
        }
    }
    else if (DropDownList2.SelectedItem.Text == "Texas")
    {

        DropDownList3.Items.Clear();
        l3.Add(" ");
        l3.Add("Archer City");
        l3.Add("Bryan");


        foreach (string item in l3)
        {
            DropDownList3.Items.Add(item);
        }
    }

}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
    Label4.Text = DropDownList1.SelectedItem.Text.ToString() + " " + DropDownList2.SelectedItem.Text.ToString() + " " + DropDownList3.SelectedItem.Text.ToString();
}
}
 
Share this answer
 
v2
Comments
SubhashRokzzz 25-Feb-15 6:12am    
I use the same code.. except i have added triggers on update panel.Its not working
FinickyCoder 25-Feb-15 6:56am    
no need to use trigger if u are placing all your controls in one and the same update panel

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