Formatting Cell Number Value Separate From LayoutSettings Culture

16 replies. Last post: June 7, 2011 9:50 AM by A Yousif
Tags :
  • (None)
  • New Discussion
  • New Question
  • New Product Feedback
A YousifMember

We have a few grids that require the user see the currency figures for a specific currency format which may not be the same as the grid's culture.  For example, the user may have the grid culture set to en-US but wants to see the currency formatted in Euros via en-IE for Ireland or maybe formatted for pt-BR.  The reason we can't set the entire grid culture is we don't want to affect any other columns like dates or other numbers that need to stay formatted for the en-US culture.

I can't find a way to do this right now so I need some help in doing this please.  I've tried overriding the InitializeCell but this is not working.  The grid overrides my format when it renders.

Here's my OnInitializeCell override.

public override bool OnInitializeCell(WebGridCell cell)
{
    bool bRet = base.OnInitializeCell(cell);

    if (cell.Column.ColumnType != ColumnType.Text)
    {
        return bRet;
    }

    DataRow[] drFilteredRows = m_dtColumns.Select(
"columnName = \'" + cell.Column.Name + "\'");
if (drFilteredRows != null && drFilteredRows.Length > 0) { DataRow dr = drFilteredRows[0]; if (!string.IsNullOrEmpty(cell.Column.DataFormatString) &&
cell.Column.DataFormatString.StartsWith("C")) { if (!string.IsNullOrEmpty(cell.Text)) { cell.Text = ((decimal)cell.Value).ToString(
cell.Column.DataFormatString,new CultureInfo("pt-BR")); } } } return bRet; }

The above is hard-coded to format using the Brazillian Real as an override but after rendering, it shows up in the US dollar format.

So 123456789.53 should show up as "R$ 123.456.789,53" and not "$123,456,789.53" as it does now.  So how do I accomplish this please?  Thanks.

 

All times are GMT -5. The time now is 1:49 AM.
Previous Next