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

Conditionally format a cell in a grid

1 Answer 107 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mgroesink
Top achievements
Rank 1
mgroesink asked on 16 Apr 2008, 03:15 PM
I have a RadGrid with columns that are created at runtime.
Data cells contain values like A6754 (NB).
I want to set a backcolor for the cells that depends on the letters between the brackets NB in this example.

How do I loop through all the cells in the grid and change the backcolor of the cells? I think the solution will be very easy, but I cannot find it.

Thanks for any advice.

1 Answer, 1 is accepted

Sort by
0
plamen
Top achievements
Rank 1
answered on 16 Apr 2008, 04:18 PM
hi :)

You can use the ItemDataBound event handler

Here is an example:

    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem gridDataItem = (GridDataItem)e.Item; 
            DataRowView dataRowView = (DataRowView)(e.Item.DataItem); 
            if (dataRowView.Row["MyColumnName"].ToString() == "TestCondition"
            { 
                gridDataItem["MyColumnName"].BackColor = System.Drawing.Color.Red; 
            }             
        } 
    } 



Cheers...
<John:Peel />
Tags
Grid
Asked by
mgroesink
Top achievements
Rank 1
Answers by
plamen
Top achievements
Rank 1
Share this question
or