Showing posts with label Code Snipets. Show all posts
Showing posts with label Code Snipets. Show all posts

Dec 6, 2007

World Countries Drop Down List Code

I am sure you might need to load world countries drop down list, if you are developing system.

Well, today I found that existing country drop down codes din't have value for each of list items.
First idea in my mind was, start adding codes line by line ... walao !!!

Until added for about 20 lines, I was frustrated and I am not going to do that for the rest of few hundreds line!!

Luckly, my brain still working... I found a easy logic to solve it.

Share with you all, may be you will need it one day. Because this piece of code is wanted & re-usable.


Private Sub LoadCountryDropdownList()

dropCountry.Items.Clear
dropCountry.Items.Add("Afghanistan")
dropCountry.Items.Add("Albania")
dropCountry.Items.Add("Algeria")
dropCountry.Items.Add("American Samoa")
dropCountry.Items.Add("Andorra")
dropCountry.Items.Add("Angola")
dropCountry.Items.Add("Anguilla")
dropCountry.Items.Add("Antarctica")
dropCountry.Items.Add("Antigua and Barbuda")
dropCountry.Items.Add("Argentina")
dropCountry.Items.Add("Armenia")
dropCountry.Items.Add("Aruba")
dropCountry.Items.Add("Australia")
dropCountry.Items.Add("Austria")
dropCountry.Items.Add("Azerbaijan")
dropCountry.Items.Add("Bahamas")
dropCountry.Items.Add("Bahrain")
dropCountry.Items.Add("Bangladesh")
dropCountry.Items.Add("Barbados")
dropCountry.Items.Add("Belarus")
dropCountry.Items.Add("Belgium")
dropCountry.Items.Add("Belize")
dropCountry.Items.Add("Benin")
dropCountry.Items.Add("Bermuda")
dropCountry.Items.Add("Bhutan")
dropCountry.Items.Add("Bolivia")
dropCountry.Items.Add("Bosnia and Herzegovina")
dropCountry.Items.Add("Botswana")
dropCountry.Items.Add("Bouvet Island")
dropCountry.Items.Add("Brazil")
dropCountry.Items.Add("British Indian Ocean Territory")
dropCountry.Items.Add("Brunei")
dropCountry.Items.Add("Bulgaria")
dropCountry.Items.Add("Burkina Faso")
dropCountry.Items.Add("Burundi")
dropCountry.Items.Add("Cambodia")
dropCountry.Items.Add("Cameroon")
dropCountry.Items.Add("Canada")
dropCountry.Items.Add("Cape Verde")
dropCountry.Items.Add("Cayman Islands")
dropCountry.Items.Add("Central African Republic")
dropCountry.Items.Add("Chad")
dropCountry.Items.Add("Chile")
dropCountry.Items.Add("China")
dropCountry.Items.Add("Christmas Island")
dropCountry.Items.Add("Cocos (Keeling) Islands")
dropCountry.Items.Add("Colombia")
dropCountry.Items.Add("Comoros")
dropCountry.Items.Add("Congo")
dropCountry.Items.Add("Cook Islands")
dropCountry.Items.Add("Costa Rica")
dropCountry.Items.Add("C魌e d'Ivoire")
dropCountry.Items.Add("Croatia (Hrvatska)")
dropCountry.Items.Add("Cuba")
dropCountry.Items.Add("Cyprus")
dropCountry.Items.Add("Czech Republic")
dropCountry.Items.Add("Congo (DRC)")
dropCountry.Items.Add("Denmark")
dropCountry.Items.Add("Djibouti")
dropCountry.Items.Add("Dominica")
dropCountry.Items.Add("Dominican Republic")
dropCountry.Items.Add("East Timor")
dropCountry.Items.Add("Ecuador")
dropCountry.Items.Add("Egypt")
dropCountry.Items.Add("El Salvador")
dropCountry.Items.Add("Equatorial Guinea")
dropCountry.Items.Add("Eritrea")
dropCountry.Items.Add("Estonia")
dropCountry.Items.Add("Ethiopia")
dropCountry.Items.Add("Falkland Islands (Islas Malvinas)")
dropCountry.Items.Add("Faroe Islands")
dropCountry.Items.Add("Fiji Islands")
dropCountry.Items.Add("Finland")
dropCountry.Items.Add("France")
dropCountry.Items.Add("French Guiana")
dropCountry.Items.Add("French Polynesia")
dropCountry.Items.Add("French Southern and Antarctic Lands")
dropCountry.Items.Add("Gabon")
dropCountry.Items.Add("Gambia")
dropCountry.Items.Add("Georgia")
dropCountry.Items.Add("Germany")
dropCountry.Items.Add("Ghana")
dropCountry.Items.Add("Gibraltar")
dropCountry.Items.Add("Greece")
dropCountry.Items.Add("Greenland")
dropCountry.Items.Add("Grenada")
dropCountry.Items.Add("Guadeloupe")
dropCountry.Items.Add("Guam")
dropCountry.Items.Add("Guatemala")
dropCountry.Items.Add("Guinea")
dropCountry.Items.Add("GuineaBissau")
dropCountry.Items.Add("Guyana")
dropCountry.Items.Add("Haiti")
dropCountry.Items.Add("Heard Island and McDonald Islands")
dropCountry.Items.Add("Honduras")
dropCountry.Items.Add("Hong Kong SAR")
dropCountry.Items.Add("Hungary")
dropCountry.Items.Add("Iceland")
dropCountry.Items.Add("India")
dropCountry.Items.Add("Indonesia")
dropCountry.Items.Add("Iran")
dropCountry.Items.Add("Iraq")
dropCountry.Items.Add("Ireland")
dropCountry.Items.Add("Israel")
dropCountry.Items.Add("Italy")
dropCountry.Items.Add("Jamaica")
dropCountry.Items.Add("Japan")
dropCountry.Items.Add("Jordan")
dropCountry.Items.Add("Kazakhstan")
dropCountry.Items.Add("Kenya")
dropCountry.Items.Add("Kiribati")
dropCountry.Items.Add("Korea")
dropCountry.Items.Add("Kuwait")
dropCountry.Items.Add("Kyrgyzstan")
dropCountry.Items.Add("Laos")
dropCountry.Items.Add("Latvia")
dropCountry.Items.Add("Lebanon")
dropCountry.Items.Add("Lesotho")
dropCountry.Items.Add("Liberia")
dropCountry.Items.Add("Libya")
dropCountry.Items.Add("Liechtenstein")
dropCountry.Items.Add("Lithuania")
dropCountry.Items.Add("Luxembourg")
dropCountry.Items.Add("Macau SAR")
dropCountry.Items.Add("Macedonia Former Yugoslav Republic of")
dropCountry.Items.Add("Madagascar")
dropCountry.Items.Add("Malawi")
dropCountry.Items.Add("Malaysia")
dropCountry.Items.Add("Maldives")
dropCountry.Items.Add("Mali")
dropCountry.Items.Add("Malta")
dropCountry.Items.Add("Marshall Islands")
dropCountry.Items.Add("Martinique")
dropCountry.Items.Add("Mauritania")
dropCountry.Items.Add("Mauritius")
dropCountry.Items.Add("Mayotte")
dropCountry.Items.Add("Mexico")
dropCountry.Items.Add("Micronesia")
dropCountry.Items.Add("Moldova")
dropCountry.Items.Add("Monaco")
dropCountry.Items.Add("Mongolia")
dropCountry.Items.Add("Montserrat")
dropCountry.Items.Add("Morocco")
dropCountry.Items.Add("Mozambique")
dropCountry.Items.Add("Myanmar")
dropCountry.Items.Add("Namibia")
dropCountry.Items.Add("Nauru")
dropCountry.Items.Add("Nepal")
dropCountry.Items.Add("Netherlands")
dropCountry.Items.Add("Netherlands Antilles")
dropCountry.Items.Add("New Caledonia")
dropCountry.Items.Add("New Zealand")
dropCountry.Items.Add("Nicaragua")
dropCountry.Items.Add("Niger")
dropCountry.Items.Add("Nigeria")
dropCountry.Items.Add("Niue")
dropCountry.Items.Add("Norfolk Island")
dropCountry.Items.Add("North Korea")
dropCountry.Items.Add("Northern Mariana Islands")
dropCountry.Items.Add("Norway")
dropCountry.Items.Add("Oman")
dropCountry.Items.Add("Pakistan")
dropCountry.Items.Add("Palau")
dropCountry.Items.Add("Panama")
dropCountry.Items.Add("Papua New Guinea")
dropCountry.Items.Add("Paraguay")
dropCountry.Items.Add("Peru")
dropCountry.Items.Add("Philippines")
dropCountry.Items.Add("Pitcairn Islands")
dropCountry.Items.Add("Poland")
dropCountry.Items.Add("Portugal")
dropCountry.Items.Add("Puerto Rico")
dropCountry.Items.Add("Qatar")
dropCountry.Items.Add("Reunion")
dropCountry.Items.Add("Romania")
dropCountry.Items.Add("Russia")
dropCountry.Items.Add("Rwanda")
dropCountry.Items.Add("St. Kitts and Nevis")
dropCountry.Items.Add("St. Lucia")
dropCountry.Items.Add("St. Vincent and the Grenadines")
dropCountry.Items.Add("Samoa")
dropCountry.Items.Add("San Marino")
dropCountry.Items.Add("S鉶 Tom?and Pr韓cipe")
dropCountry.Items.Add("Saudi Arabia")
dropCountry.Items.Add("Senegal")
dropCountry.Items.Add("Seychelles")
dropCountry.Items.Add("Sierra Leone")
dropCountry.Items.Add("Singapore")
dropCountry.Items.Add("Slovakia")
dropCountry.Items.Add("Slovenia")
dropCountry.Items.Add("Solomon Islands")
dropCountry.Items.Add("Somalia")
dropCountry.Items.Add("South Africa")
dropCountry.Items.Add("South Georgia and the South Sandwich Islands")
dropCountry.Items.Add("Spain")
dropCountry.Items.Add("Sri Lanka")
dropCountry.Items.Add("St. Helena")
dropCountry.Items.Add("St. Pierre and Miquelon")
dropCountry.Items.Add("Sudan")
dropCountry.Items.Add("Suriname")
dropCountry.Items.Add("Svalbard and Jan Mayen")
dropCountry.Items.Add("Swaziland")
dropCountry.Items.Add("Sweden")
dropCountry.Items.Add("Switzerland")
dropCountry.Items.Add("Syria")
dropCountry.Items.Add("Taiwan")
dropCountry.Items.Add("Tajikistan")
dropCountry.Items.Add("Tanzania")
dropCountry.Items.Add("Thailand")
dropCountry.Items.Add("Togo")
dropCountry.Items.Add("Tokelau")
dropCountry.Items.Add("Tonga")
dropCountry.Items.Add("Trinidad and Tobago")
dropCountry.Items.Add("Tunisia")
dropCountry.Items.Add("Turkey")
dropCountry.Items.Add("Turkmenistan")
dropCountry.Items.Add("Turks and Caicos Islands")
dropCountry.Items.Add("Tuvalu")
dropCountry.Items.Add("Uganda")
dropCountry.Items.Add("Ukraine")
dropCountry.Items.Add("United Arab Emirates")
dropCountry.Items.Add("United Kingdom")
dropCountry.Items.Add("United States")
dropCountry.Items.Add("United States Minor Outlying Islands")
dropCountry.Items.Add("Uruguay")
dropCountry.Items.Add("Uzbekistan")
dropCountry.Items.Add("Vanuatu")
dropCountry.Items.Add("Vatican City")
dropCountry.Items.Add("Venezuela")
dropCountry.Items.Add("Vietnam")
dropCountry.Items.Add("Virgin Islands (British)")
dropCountry.Items.Add("Virgin Islands")
dropCountry.Items.Add("Wallis and Futuna")
dropCountry.Items.Add("Yemen")
dropCountry.Items.Add("Yugoslavia")
dropCountry.Items.Add("Zambia")
dropCountry.Items.Add("Zimbabwe")

'// This is the piece of code that helps me for the rest of hundres c&p works
For Each countryItem As ListItem In dropCountry.Items
countryItem.Value = countryItem.Text.ToUpper
Next

'//You might need a default country selected.
Dim defaultCountry As String = _
System.Configuration.ConfigurationSettings.AppSettings("defaultCountry").ToString

dropCountry.Items.FindByValue(defaultCountry).Selected = True

End Sub