簡體   English   中英

RadGridView更改文本顏色

[英]RadGridView change text color

我有一個簡單的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);
}

任何輸入將不勝感激。

實際上有一個非常簡單的解決方案:

  1. 附加事件處理程序:

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

     if (((EventLogRow)e.DataElement).MsgType == EventLogger.EventType.Exception) { e.Row.Foreground = new SolidColorBrush(Colors.Red); } 

嘗試類似這樣的東西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;
        }
    }
}

或者這可以為你工作我已經測試了它並確保用你的列名替換列的名稱,如果你給我列名,因為你有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;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM