Post Pic

C# Utility method to populate list controls with world currencies

I am working on a Job File System (JFS) for a client and they had the requirement to include a drop down list of currencies on their Purchase Order and Invoice documents, at first I was going to manually put together a list control but on reflection I thought their must be a better way of doing this that is more reusable. So here I have a utility method I put together to populate a ListControl with currency options. I would be interested in any feedback on this and alternative/better methods of achieving the end result:

/// <summary>
/// Fills the ListControl with ISO currency symbols.
/// </summary>
/// <param name="ctrl">The ListControl.</param>
public static void FillWithISOCurrencySymbols(ListControl ctrl)
{
	foreach (CultureInfo cultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
	{
		RegionInfo regionInfo = new RegionInfo(cultureInfo.LCID);
		if (ctrl.Items.FindByValue(regionInfo.ISOCurrencySymbol) == null)
		{
			ctrl.Items.Add(new ListItem(regionInfo.CurrencyEnglishName, regionInfo.ISOCurrencySymbol));
		}
	}

	RegionInfo currentRegionInfo = new RegionInfo(CultureInfo.CurrentCulture.LCID);

	//- Default the selection to the current cultures currency symbol
	if (ctrl.Items.FindByValue(currentRegionInfo.ISOCurrencySymbol) != null)
	{
		ctrl.Items.FindByValue(currentRegionInfo.ISOCurrencySymbol).Selected = true;
	}
}

Related Posts

  1. C# Utility method to populate list controls with all countries as given in ISO 3166-1
  2. UCommerce for Umbraco Extension Method – ISO 3166 Numeric Country Codes

Related posts brought to you by Yet Another Related Posts Plugin.

One Response

[...] 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 [...]

Leave Your Response

* Name, Email, Comment are Required

Umbraco Certified Developer
FreshBooks
ElasticHosts: Flexible Servers in the Cloud
SagePay Approved Partner
Microsoft WebsiteSpark