
Most projects I work on need a list of countries at some point so I put together a snippet of SQL that I could reuse to create and populate a countries table in the database with all countries as given in ISO 3166-1. After recently writing a utility class to populate list controls with world currencies according to ISO 4217 it got me wondering if I could also do the same for countries using only the .Net Framework. And so I came up with the following utility class to do the job.
/// <summary>
/// Populates the list control with countries as given by ISO 4217.
/// </summary>
/// <param name="ctrl">The list control to populate.</param>
public static void FillWithISOCountries(ListControl ctrl)
{
foreach (CultureInfo cultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
RegionInfo regionInfo = new RegionInfo(cultureInfo.LCID);
if (ctrl.Items.FindByValue(regionInfo.TwoLetterISORegionName) == null)
{
ctrl.Items.Add(new ListItem(regionInfo.EnglishName, regionInfo.TwoLetterISORegionName));
}
}
RegionInfo currentRegionInfo = new RegionInfo(CultureInfo.CurrentCulture.LCID);
//- Default the selection to the current cultures country
if (ctrl.Items.FindByValue(currentRegionInfo.TwoLetterISORegionName) != null)
{
ctrl.Items.FindByValue(currentRegionInfo.TwoLetterISORegionName).Selected = true;
}
}
More From ProNotion
Related Posts
- C# Utility method to populate list controls with world currencies
- UCommerce for Umbraco Extension Method – ISO 3166 Numeric Country Codes
Related posts brought to you by Yet Another Related Posts Plugin.







5 Responses
Hurray for System.Globalization!!!
high five you rock!!!!
Great bit of code that!
FAIL! GetCulters does not return a complete list of countries. It returns cultures. You will find the country “Cuba” and others missing from your list. I have found no way for Windows or .NET to provide you the complete list that matches the ISO 3166-1. If you look at Windows Control Panel Region and Language and the Location Tab the drop down there shows a list of all countries however this data is not in the registry or provided by .NET
It seems you are correct, it is not showing an entirely complete list. For now it serves it’s purpose where I am using it, if it doesn’t fit your needs you can always put together an alternative solution for your requirements.
Please free to post a solution back here if you find a way to produce a more complete list.