4

我有一个简单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);
}

任何输入将不胜感激。

4

2 回答 2

4

实际上有一个非常简单的解决方案:

  1. 附加事件处理程序:

    EventLogGrid.RowLoaded += EventLogGrid_RowLoaded;
    
  2. 更改行的颜色:

    if (((EventLogRow)e.DataElement).MsgType == EventLogger.EventType.Exception)
    {
       e.Row.Foreground = new SolidColorBrush(Colors.Red);
    }
    
于 2012-12-31T21:06:42.360 回答
1

尝试类似的方法 Telerik 网站也有大量很棒的示例Telerik Radgrid 概览

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;
        }
    }
}

或者这对你有用这对你来说很有意义

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;
    }
}
于 2012-12-31T16:04:24.960 回答