gpt4 book ai didi

c# - 设置 Telerik RadGrid 的行颜色

转载 作者:行者123 更新时间:2023-11-30 15:28:47 25 4
gpt4 key购买 nike

我正在使用 RadGrid 来显示数据库中的数据。如果在状态列中该行显示为“REJECTED”,我想将 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)
{
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;
}
}
}

让我知道它是否适合您。

关于c# - 设置 Telerik RadGrid 的行颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24947598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com