我有一个简单的RadGridView
,其中我想要更改特定行(= 3个单元格)的文本颜色。不幸的是,这段代码不起作用:
//add new row to the grid
EventLogGrid.Items.Add(new EventLogRow(eventType, occured, msg));
//change the color of the text of all cells if it's an exception
if (eventType == EventLogger.EventType.Exception)
{
var rows = this.EventLogGrid.ChildrenOfType<GridViewRow>();
rows.Last().Foreground = new SolidColorBrush(Colors.Yellow);
}
任何意见都会受到赞赏。
答案 0 :(得分:4)
实际上有一个非常简单的解决方案:
附加事件处理程序:
EventLogGrid.RowLoaded += EventLogGrid_RowLoaded;
更改行的颜色:
if (((EventLogRow)e.DataElement).MsgType == EventLogger.EventType.Exception)
{
e.Row.Foreground = new SolidColorBrush(Colors.Red);
}
答案 1 :(得分:1)
尝试这样的事情,Telerik网站还有很多很棒的例子Telerik Radgrid Overview
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
//Check if the Item is a GridDataItem
if (e.Item is GridDataItem)
{
GridDataItem dataBoundItem = e.Item as GridDataItem;
if (int.Parse(dataBoundItem["yourColounName"].Text) == "Date")
{
dataBoundItem["yourColounName"].ForeColor = Color.Red;
dataBoundItem["yourColounName"].Font.Bold = true;
}
}
}
或者这可以为你工作我已经测试了它并确保用你的列名替换列的名称,如果你给我列名,因为你有3列我需要拳头列名..希望这对你有意义
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
TableCell cell = (TableCell)item["YourColumnName"];
cell.BackColor = System.Drawing.Color.Yellow;
}
}