gpt4 book ai didi

c# - 更改特定行的颜色 (TELERIK)

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

我的网格中有一个显示“INDEF”或“MA”的 GridTemplateColumn。当它是“INDEF”时,我希望我的行改变颜色:

这是我的尝试:

protected void grid_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
Label lbl = (Label)item.FindControl("test");
if (lbl.Text == "INDEF")
{
lbl.ForeColor = System.Drawing.Color.Red;
}
}
}

使用相关列的代码:

              <telerik:GridTemplateColumn  HeaderText="Type de tickets"
UniqueName="typedestickets">
<ItemTemplate><asp:Label id="test" runat="server"></asp:Label></ItemTemplate>
</telerik:GridTemplateColumn>

但是我通过添加断点注意到 e.Item 不是 GridDataItem 而是 GridPagerItem(我不知道为什么)

所以我尝试了这个:(也没有用)

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item is GridPagerItem)
{
GridPagerItem item = (GridPagerItem)e.Item;
Label lbl = (Label)item.FindControl("test");



if (lbl.Text == "INDEF")
{
lbl.ForeColor = System.Drawing.Color.Red;
item.BackColor = System.Drawing.Color.Red;
lbl.BackColor = System.Drawing.Color.Red;

}
}
}

预先感谢您的帮助

最佳答案

试试这个

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
//Is it a GridDataItem
if (e.Item is GridDataItem)
{
//Get the instance of the right type
GridDataItem dataBoundItem = e.Item as GridDataItem;

//Check the formatting condition
if (int.Parse(dataBoundItem["typedestickets"].Text) =="INDEF")
{
dataBoundItem["typedestickets"].ForeColor = Color.Red;
dataBoundItem["typedestickets"].Font.Bold = true;
//Customize more...
}
}
}

关于c# - 更改特定行的颜色 (TELERIK),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9565173/

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