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

[Solved] turn cell value red if negative

3 Answers 270 Views
Grid
This is a migrated thread and some comments may be shown as answers.
appdev
Top achievements
Rank 1
appdev asked on 02 Oct 2009, 01:39 PM
how would i turn the cell value red when the value in that cell is a negative number. thanks.

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 02 Oct 2009, 01:56 PM
Hello Duy,

I recommend you examine the following link:
Conditional Formatting for rows/cells on ItemDataBound

Let us know if you need further assistance.

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
appdev
Top achievements
Rank 1
answered on 02 Oct 2009, 02:02 PM
ah but that would require me to know the column header name. Is there a way to do it dynamically?
0
Daniel
Telerik team
answered on 08 Oct 2009, 08:20 AM
Hello Duy,

Please try the following approach:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    if (e.Item is GridDataItem) 
    { 
        foreach (TableCell cell in e.Item.Cells) 
        { 
            int value; 
            if (int.TryParse(cell.Text, out value)) 
                cell.Style["color"] = value < 0 ? "red" : "blue"
        } 
    } 

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
appdev
Top achievements
Rank 1
Answers by
Daniel
Telerik team
appdev
Top achievements
Rank 1
Share this question
or