设置Telerik RadGrid的行颜色
本文关键字:颜色 RadGrid Telerik 设置 | 更新日期: 2023-09-27 18:14:37
我使用RadGrid来显示来自数据库的数据。我想把RadGrid中的行颜色改为红色,如果在状态列中行显示为"拒绝"。如果状态为NULL,则该行将继续显示为白色。我已经尝试了这个代码,但行仍然没有改变颜色为红色。
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
{ }
试试这样:
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;
}
}
}
让我知道它是否适合你