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

Background row color based on a column value

1 Answer 187 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lon
Top achievements
Rank 1
Lon asked on 08 Aug 2014, 05:43 PM
I am trying to convert a gridview to a radgrid.

One issue I am having is to get certain rows to highlight with the color yellow when it matches the value of a specific column.

The grid view code works fine. The radgrid does not.
Radgrid is using a skin (web blue) so I am thinking that may be the issue.

Any help is appreciated.

 protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // determine the value of the ViewableByClient field
            bool ViewableByClient =
             Convert.ToBoolean(DataBinder.Eval(e.Row.DataItem,
             "ViewableByClient"));
            if (ViewableByClient)
                // color the background of the row yellow
                e.Row.BackColor = Color.Yellow;
        }
    }

protected void RadGrid3_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // determine the value of the ViewableByClient field
            bool ViewableByClient =
             Convert.ToBoolean(DataBinder.Eval(e.Row.DataItem,
             "ViewableByClient"));
            if (ViewableByClient)
                // color the background of the row yellow
                e.Row.BackColor = Color.Yellow;
        }
    }

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 11 Aug 2014, 03:45 AM
Hi Lon,

You can use the ItemDataBound event of the RadGrid to set row color based on condition. Please try the following code snippet.

C#:
protected void rgrdSample_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem dataItem=(GridDataItem)e.Item;
        bool ViewableByClient = Convert.ToBoolean(dataItem["ViewableByClient "].Text);
        if (ViewableByClient)
        {
            dataItem.BackColor = Color.Yellow;
        }
    }       
}

Thanks,
Princy
Tags
Grid
Asked by
Lon
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or