I have a repeater control which displays pricing, the currency symbol should be shown depending on the country of the specific person.
Generally, I'd just do something like:
<%# DataBinder.Eval(Container.DataItem, "CheapestLesson", "{0:C}")
However, this will take the current page culture. Is there any way to override the culture when handling the onItemDataBound event?
You can specify a different culture when the string is formatted if you use this overload of String.Format
:
<%# String.Format(new CultureInfo("en-US"), "{0:C}", DataBinder.Eval(Container.DataItem, "CheapestLesson")) %>
All CultureInfo
objects implement the IFormatProvider
interface, so if you use this overload of String.Format
you can override the current culture with a specific culture only for this formatting.