Question

I have a column which is binded with a property of type double in auto generated Telerik RadGridView.

<telerik:GridViewDataColumn
         Header="Formated Price" DataFormatString="0.###E0"
         DataMemberBinding="{Binding Price, Mode=TwoWay}">
</telerik:GridViewDataColumn>

I want multiple DataFormatString w.r.t Cell.

For example: if value in cell is greater then 5 then "Exponential value" should be shown in the cell, else value should be displayed in "rounded off with two decimal places" in the cell.

Since the table is auto generated, I can't access the single cell value, so I can change its stringFormat

The property DataFormatString="0.###E0" applies on complete column, not on a single cell.

Was it helpful?

Solution

The best thing to do in this case is to not use the default template. Instead, define your own CellTemplate (GridViewDataColumn.CellTemplate) and use a converter on the value. The converter would look something like:

class PriceConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, string language)
    {
        double price = Convert.ToDouble(value);

        if(price > 5.0)
        {
            // return the price formatted how you want
        }
        else
        {
            // return the price formatted differently
        }
    }

    public object ConvertBack(object value, Type targetType, object parameter, string language)
    {
        throw new NotImplementedException();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top