endrec
asked on
How can I display a currency value that is different than the user's culture in a templated grid item?
I wanted to know if there is an event/method for templated ASP.NET datagrid items where I can specifically set the culture that values are rendered in.
Example: The user is viewing the page in Japanese, but all prices need to be listed as US prices with the $ currency while all other resources need to still be in Japanese. For a specific datagrid and templated column, how can I set the culture that a particular column's values are rendered under.
Currently code like the following would show a price of 30 as 30¥ instead of $30.
<asp:TemplateColumn HeaderText="Example">
<ItemTemplate>
<asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("Price", "{0:C}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
Example: The user is viewing the page in Japanese, but all prices need to be listed as US prices with the $ currency while all other resources need to still be in Japanese. For a specific datagrid and templated column, how can I set the culture that a particular column's values are rendered under.
Currently code like the following would show a price of 30 as 30¥ instead of $30.
<asp:TemplateColumn HeaderText="Example">
<ItemTemplate>
<asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("Price", "{0:C}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
ASKER
Oh, I need to do the formatting in the code behind because the culture of the currency is coming from the property that is in the code behind (which in terms comes from the database and may not be directly bound to the datasource of the grid).
You could also do it this way:
//Change Current Culture
System.Globalization.Cultu reInfo CurrentCI = System.Threading.Thread.Cu rrentThrea d.CurrentC ulture;
System.Threading.Thread.Cu rrentThrea d.CurrentC ulture = new System.Globalization.Cultu reInfo("en -US");
//Do something.
//Return to original culture
System.Threading.Thread.Cu rrentThrea d.CurrentC ulture = CurrentCI;
//Change Current Culture
System.Globalization.Cultu
System.Threading.Thread.Cu
//Do something.
//Return to original culture
System.Threading.Thread.Cu
Check this link below to find other ways to modify culture programmatically. In my previous post, that approach is based on thread level.
http://support.microsoft.com/kb/306162
http://support.microsoft.com/kb/306162
ASKER
Which method of the datagrid would I set the culture when generating the content for the label as it must be different than the culture of the rest of the page. This is the primary issue.
You could put the culture modification in the ItemDataBound event. There are other events such as ItemCreated. It really depends on what you are doing anyway.
http://msdn.microsoft.com/en-us/library/a83x3931.aspx
http://msdn.microsoft.com/en-us/library/a83x3931.aspx
Also, you could apply the culture modification, something like this.
//Change Current Culture
System.Globalization.Cultu reInfo CurrentCI = System.Threading.Thread.Cu rrentThrea d.CurrentC ulture;
System.Threading.Thread.Cu rrentThrea d.CurrentC ulture = new System.Globalization.Cultu reInfo("en -US");
//Do Something
ItemsGrid.DataSource= CreateDataSource();
ItemsGrid.DataBind();
//Return to original culture
System.Threading.Thread.Cu rrentThrea d.CurrentC ulture = CurrentCI;
//Change Current Culture
System.Globalization.Cultu
System.Threading.Thread.Cu
//Do Something
ItemsGrid.DataSource= CreateDataSource();
ItemsGrid.DataBind();
//Return to original culture
System.Threading.Thread.Cu
I've requested that this question be deleted for the following reason:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<asp:TemplateColumn HeaderText="Example">
<ItemTemplate>
<asp:Label ID="PriceLabel" runat="server" Text='<%# string.Format(new System.Globalization.Cultu
</ItemTemplate>
</asp:TemplateColumn>