Conditionally format a cell in a grid

2 posts, 0 answers
  1. mgroesink
    mgroesink avatar
    5 posts
    Member since:
    Mar 2007

    Posted 16 Apr 2008 Link to this post

    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.
  2. John
    John avatar
    416 posts
    Member since:
    Oct 2006

    Posted 16 Apr 2008 Link to this post

    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; 

    <John:Peel />
Back to Top