This is a migrated thread and some comments may be shown as answers.

How to render the value in a templated RadGrid column in a specific culture and which RadGrid event to do this in?

2 Answers 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jgill
Top achievements
Rank 1
jgill asked on 18 May 2011, 02:32 PM

I wanted to know if there is an event/method for templated RadGrid columns/items where I can specifically set the culture that a specific templated value is rendered in separately from the culture used on the rest of the page/values.

Example:  The user is viewing the page in Japanese and that is the culture for the overall site, but all prices in a certain column in a RadGrid 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.  In the code behind (not declaratively), when binding occurs I need to be abel to say that the price should render in the en-US culture, en-GB, etc.


<telerik:GridTemplateColumn UniqueName="ExamplePriceArea" ReadOnly="True" HeaderText="ExamplePrice">
    <ItemTemplate>
        <asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("Price", "{0:C}") %>'></asp:Label>
    </ItemTemplate>
</telerik:GridTemplateColumn>

2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 24 May 2011, 10:15 PM
Hello Jgill,

Please try the following approach:
<telerik:GridTemplateColumn UniqueName="ExamplePriceArea" ReadOnly="True" HeaderText="ExamplePrice">
    <ItemTemplate>
        <asp:Label ID="PriceLabel" runat="server" Text='<%# ConvertValue(Eval("Price")) %>'></asp:Label>
    </ItemTemplate>
</telerik:GridTemplateColumn>

protected string ConvertValue(object val)
{
    return ((double)val).ToString("C", CultureInfo.CreateSpecificCulture("en-US"));
}

Best regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
jgill
Top achievements
Rank 1
answered on 25 May 2011, 12:38 AM
Remarkably simple!  Works!
Tags
Grid
Asked by
jgill
Top achievements
Rank 1
Answers by
Daniel
Telerik team
jgill
Top achievements
Rank 1
Share this question
or