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

Zero as empty string - GridViewDecimalColumn

2 Answers 145 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Amige
Top achievements
Rank 1
Veteran
Amige asked on 05 Jul 2017, 09:40 PM

I have several GridViewDecimalColumn columns, and I am using this string format: {0:N3}, I want to show 3 decimals, but if the value is zero I would like to show the value as an empty string.

 

1.12 = 1.120

0.8 = 0.800

2.9 = 2.900

0.0 = " " ?

Is there a way to accomplish this?

Regards,

Alberto

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 06 Jul 2017, 06:20 AM
Hello Alberto,

You can use the CellFormatting event to change the text of the cell:
private void RadGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    if (e.Column is GridViewDecimalColumn && e.CellElement.Value != null)
    {
        var value =(decimal)e.CellElement.Value;
        if (value == 0)
        {
            e.CellElement.Text = "";
        }
    }
}

I hope this will be useful. 

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Amige
Top achievements
Rank 1
Veteran
answered on 06 Jul 2017, 03:50 PM

Hello Dimitar,

That is what I was looking for.

Thanks,

Alberto

Tags
GridView
Asked by
Amige
Top achievements
Rank 1
Veteran
Answers by
Dimitar
Telerik team
Amige
Top achievements
Rank 1
Veteran
Share this question
or