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

Show Negative Number In Red Using DataFormat string

2 Answers 673 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tracy
Top achievements
Rank 1
Tracy asked on 24 Oct 2013, 05:49 PM
Hi,

Is there a way to use the dataformatstring on a gridboundcolumn to display negative numbers in red?

DataType="System.Int16" DataFormatString="{0:#,###,##0;-#,###,##0}"



Thank You
Tracy

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 25 Oct 2013, 05:10 AM
Hi Tracy,

You can set the negative numbers to be in Red,from code behind by accessing the column values.Please try the following and let me know if any concern.

ASPX:
<telerik:GridBoundColumn DataField="EmployeeID" HeaderText="EmployeeID" UniqueName="EmployeeID" DataType="System.Int16" />

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem )
    {
        GridDataItem data = (GridDataItem)e.Item;
        int value = Convert.ToInt16(data["EmployeeID"].Text);
        if (value < 0)
        {
            data["EmployeeID"].ForeColor = Color.Red;
        }
    }
}

Thanks,
Princy
0
Tracy
Top achievements
Rank 1
answered on 25 Oct 2013, 02:43 PM
Hi Princy,

Thanks for your response.  I was just hoping I could do it with the DataFormatString.

Thank You
Tracy
Tags
Grid
Asked by
Tracy
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Tracy
Top achievements
Rank 1
Share this question
or