Skip to content

Getting ISO Currency Codes and placing into DropDown List

February 14, 2012

Here’s the old chestnut of needing to place ISO Currency Codes into a drop down list for selecting currency (useful for international purchasing shown on your site).

I had devised the following method GetCurrencyCodes() that lists all the ISOCurrencySymbols obtained from the Windows Registry and places them in an IList, and you can set your drop down list source to this method.

static private IList<RegionInfo> GetCurrencyCodes()
{
IList<RegionInfo> regions = new List<RegionInfo>();

foreach (CultureInfo cultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
RegionInfo regionInfo = new RegionInfo(cultureInfo.LCID);

if (!regions.Any<RegionInfo>(x => x.ISOCurrencySymbol == regionInfo.ISOCurrencySymbol))
regions.Add(regionInfo);
}

return regions;
}

Main Code

ddlCurrency.DataSource = GetCurrencyCodes();
ddlCurrency.DataTextField = “CurrencyEnglishName”;
ddlCurrency.DataValueField = “ISOCurrencySymbol”;
ddlCurrency.DataBind();

 

However looking from the code, ideally it would be nice to have the ISO Currency Symbol and the full term placed in the drop down list as a text string e.g. British Bound (GBP), hence the better solution is to embed from the RegionInfo object both the CurrencyEnglishName and ISOCurrencySymbol inside a ListItem (or to which ever values you want, see http://msdn.microsoft.com/en-us/library/system.globalization.regioninfo.currencysymbol(v=vs.71).aspx

Here’s the code for this:-

solution
——–

private void GetCurrencyCodes()
{
IList<RegionInfo> regions = new List<RegionInfo>();

foreach (CultureInfo cultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
RegionInfo regionInfo = new RegionInfo(cultureInfo.LCID);

if (!regions.Any<RegionInfo>(x => x.ISOCurrencySymbol == regionInfo.ISOCurrencySymbol))
regions.Add(regionInfo);
ListItem li = new ListItem(regionInfo.CurrencyEnglishName + ” (” + regionInfo.ISOCurrencySymbol + “)”, regionInfo.ISOCurrencySymbol);
ddlCurrency.Items.Add(li);
}
}

Main Code

GetCurrencyCodes();

ddlCurrency.DataBind();

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: