C# 设置Telerik RadGrid的行颜色
我使用RadGrid显示数据库中的数据。如果在状态列中该行显示为“已拒绝”,我想将RadGrid中的行颜色更改为红色。如果状态为NULL,则行将保持显示为白色。我已尝试此代码,但行仍然没有将颜色更改为红色C# 设置Telerik RadGrid的行颜色,c#,telerik,radgrid,C#,Telerik,Radgrid,我使用RadGrid显示数据库中的数据。如果在状态列中该行显示为“已拒绝”,我想将RadGrid中的行颜色更改为红色。如果状态为NULL,则行将保持显示为白色。我已尝试此代码,但行仍然没有将颜色更改为红色 try { if (dataBoundItem["status"].Text == "REJECTED") { TableCell cell = (TableCell)dataBoundItem["status"]; cell.BackColor
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)
{
TableCell celltoVerify1 = dataBoundItem["status"];
GridDataItem dataBoundItem = e.Item as GridDataItem;
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;
}
}
}
让我知道它是否适合您。您能提供radgrid标记代码吗?嗨,我可以知道dataBoundItem是什么意思吗?是否为RadGrid ID?@GohHan“dataBoundItem”用于获取正确类型的距离