Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET list
Hi ,
I want to use States and cities of USA in listview. How i can add them all. as there are hundred of them.
Anyone can please provide me the list in c# file of USA states and cities so that i can add it.
Or how i can add all of them.
 
Need Help
Shan Khan
Posted 12-Apr-13 1:47am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Here is a states dictionary:
 
public string stateAbbreviationExpand(string abbr)
{
Dictionary<string,> states = new Dictionary<string,>();

states.Add("AL", "Alabama");
states.Add("AK", "Alaska");
states.Add("AZ", "Arizona");
states.Add("AR", "Arkansas");
states.Add("CA", "California");
states.Add("CO", "Colorado");
states.Add("CT", "Connecticut");
states.Add("DE", "Delaware");
states.Add("DC", "District of Columbia");
states.Add("FL", "Florida");
states.Add("GA", "Georgia");
states.Add("HI", "Hawaii");
states.Add("ID", "Idaho");
states.Add("IL", "Illinois");
states.Add("IN", "Indiana");
states.Add("IA", "Iowa");
states.Add("KS", "Kansas");
states.Add("KY", "Kentucky");
states.Add("LA", "Louisiana");
states.Add("ME", "Maine");
states.Add("MD", "Maryland");
states.Add("MA", "Massachusetts");
states.Add("MI", "Michigan");
states.Add("MN", "Minnesota");
states.Add("MS", "Mississippi");
states.Add("MO", "Missouri");
states.Add("MT", "Montana");
states.Add("NE", "Nebraska");
states.Add("NV", "Nevada");
states.Add("NH", "New Hampshire");
states.Add("NJ", "New Jersey");
states.Add("NM", "New Mexico");
states.Add("NY", "New York");
states.Add("NC", "North Carolina");
states.Add("ND", "North Dakota");
states.Add("OH", "Ohio");
states.Add("OK", "Oklahoma");
states.Add("OR", "Oregon");
states.Add("PA", "Pennsylvania");
states.Add("RI", "Rhode Island");
states.Add("SC", "South Carolina");
states.Add("SD", "South Dakota");
states.Add("TN", "Tennessee");
states.Add("TX", "Texas");
states.Add("UT", "Utah");
states.Add("VT", "Vermont");
states.Add("VA", "Virginia");
states.Add("WA", "Washington");
states.Add("WV", "West Virginia");
states.Add("WI", "Wisconsin");
states.Add("WY", "Wyoming");
if (states.ContainsKey(abbr))
return (states[abbr]);
/* error handler is to return an empty string rather than throwing an exception */
return "";
}
 
You can add the cities in a dictionary tree likewise
  Permalink  
Comments
shanalikhan at 12-Apr-13 6:52am
   
there are many cities , do i have to manually add the cities ? it will take alot of time . is there any 3rd party tool which will provide me the cities with respoect to states
tumbledDown2earth at 12-Apr-13 7:13am
   
you can get a datafile dump from here:
http://www.codeproject.com/Questions/154877/Need-database-for-all-countries-state-city

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

  Print Answers RSS
0 OriginalGriff 190
1 Jochen Arndt 155
2 PIEBALDconsult 150
3 Afzaal Ahmad Zeeshan 120
4 DamithSL 115
0 OriginalGriff 5,695
1 DamithSL 4,591
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 12 Apr 2013
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