Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP:NET
if we select country in dropdownlist(like india) and then next dropdownlist show state ( like delhi) show in dropdownlist in asp.net
Posted 22-Aug-12 0:32am
M@anish1.3K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try this:
 
First make AutoPostBack true Property in Drop_country Dropdown then
 
please write in page load :
 
       if(!ispostback)
       {
              FillDropDownList();
       }
    
 
------>
 
 private void FillDropDownList()
    {
        DataSet ds = new DataSet();
        SqlDataAdapter myda = new SqlDataAdapter("select Country from table name",connection object);
        myda.Fill(ds);
        drop_country.DataSource = ds;
        drop_country.DataValueField = "Country";
        drop_country.DataBind();
    }
and double click on Drop_Country Dropdown
protected void drop_country_SelectedIndexChanged(object sender, EventArgs e)
{
    DataSet ds = new DataSet();
        SqlDataAdapter myda = new SqlDataAdapter("select state from table name where country='"+Drop_contry.Selecteditem.Value+"'",connection object);
        myda.Fill(ds);
        drop_state.DataSource = ds;
        drop_state.DataValueField = "state";
        drop_state.DataBind();
}
if any Doubt please post it....
  Permalink  
v2
Comments
M@anish at 22-Aug-12 8:26am
   
your code is really work but when i select country name like usa that time only one value show in another dropdownlist it mean only one value show from state so what should i do now
and thank for that.
AshishChaudha at 22-Aug-12 8:36am
   
What exactly you are doing and whats your requirement, please make it clear??
AshishChaudha at 22-Aug-12 8:35am
   
my 5+
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Hi ,
check this Solution
how to bind the dropdown list to another dropdown list[^]
Best Regards
M.Mitwalli
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

How to do this is widely documented on the web. I believe the ASP.NET AJAX library has controls for this if you prefer to not program, but doing it with AJAX itself via jquery is both trivial and widely documented.
 
You can also do a postback, but that would be ugly, in this day and age.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

First make AutoPostBack true Property in Drop_country Drop down list after slow your error.
  Permalink  

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

  Print Answers RSS
0 Maciej Los 245
1 OriginalGriff 210
2 Manfred R. Bihy 190
3 CHill60 180
4 _Amy 155
0 OriginalGriff 7,445
1 Sergey Alexandrovich Kryukov 6,177
2 Maciej Los 3,774
3 Peter Leow 3,478
4 CHill60 2,702


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 22 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100