Click here to Skip to main content
16,004,458 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two combo boxes one for country and the second is for states the second one should load based on the value selected in the country combobox. I am populating the country combobox in following way:

C#
private void PopulateCountryComboBox()
{
     RegionInfo country = new RegionInfo(new CultureInfo("en-US", false).LCID);
     List<string> countryNames = new List<string>();
     foreach (CultureInfo cul in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
     {
          country = new RegionInfo(new CultureInfo(cul.Name, false).LCID);
          countryNames.Add(country.DisplayName.ToString() );
     }
     IEnumerable<string> nameAdded = countryNames.OrderBy(names => names).Distinct();
     foreach (string item in nameAdded)  {CountryComboBox.Items.Add(item);}
}


How can I bind the states list on the selected index change of country combobox?
Any positive responses will be appreciated.
Posted
Updated 16-Mar-15 0:46am
v2
Comments
Andy Lanng 16-Mar-15 6:49am    
Have you tried setting the country combo to postback on the SelectedIndexChange event?
This can be done via an ajax method on the client side also.
Sujith Karivelil 16-Mar-15 7:04am    
everything works fine up to this. from where i choose the list of states for the selected country without using database? that's my problem. does RegionInfo is helpfull to get the list of states
Maciej Los 16-Mar-15 7:18am    
If you mean you want to fetch State/Province/Region/Voivodeship, etc., No, it does not help you. You need to create database.

I found this resource Geographing Database dump[^] through a giyf search. There is nothing built in to .Net that can provide this info. Culture info is not anywhere near exhaustive and definitely won't include such resolution as states and counties.

PS - I did see US and UK county dbs on that site - no idea if it works tho :S
 
Share this answer
 
You can handle the SelectedIndexChanged[^] event and inside the handler, you can change the value of the second ComboBox, like this,

C#
void comboBox_SelectedIndexChanged(object sender, EventArgs e) {
   // Handle the event here...
   // Sender = your ComboBox; cast it to ComboBox
   // Get the SelectedIndex and see which country is selected
   // Find the states for that country... And populate the second control
}


This way, you can handle the change in first combo box, and depending on the value of SelectedIndex you can then search for the states for that country, and write them in the second combo box.
 
Share this answer
 

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