Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set row color of Telerik RadGrid

I am using a RadGrid for displaying the data from a database. I want to change the row color in the RadGrid to red if in the status column that row shows as "REJECTED". If the status is NULL then the row will remain displaying as the color white. I have tried this code but the row still does not change the color to red.

try
{
    if (dataBoundItem["status"].Text == "REJECTED")
    {
        TableCell cell = (TableCell)dataBoundItem["status"];
        cell.BackColor = System.Drawing.Color.Red;
        dataBoundItem.BackColor = System.Drawing.Color.Red;

        if (e.Item is GridDataItem)
        {
            GridDataItem dataBoundItem1 = e.Item as GridDataItem;

            if (dataBoundItem1["Status"].Text != null)
            {
                cell.BackColor = System.Drawing.Color.Red;
                dataBoundItem1.BackColor = Color.Red;
                dataBoundItem1["status"].ForeColor = Color.Red;
                dataBoundItem1["status"].Font.Bold = true;
            }
        }
    }
}
catch
{ }
like image 381
Ifwat Ibrahim Avatar asked Nov 01 '25 09:11

Ifwat Ibrahim


1 Answers

Try something like this:

using System.Drawing;
 
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
 {
  if (e.Item is GridDataItem)
    {
     GridDataItem dataBoundItem = e.Item as GridDataItem;
     TableCell celltoVerify1 = dataBoundItem["status"];
       if (celltoVerify1.Text== "REJECTED")
        {
            celltoVerify1.ForeColor =  Color.Red;/// Only Change Cell Color
            dataBoundItem.ForeColor = Color.Yellow; /// Change the row Color
            //celltoVerify1.Font.Bold = true;
            //celltoVerify1.BackColor = Color.Yellow;
        }
    }
 }

Let me know if it works for you.

like image 172
FeliceM Avatar answered Nov 03 '25 00:11

FeliceM