문제

I have a simple RadGridView in which I want to change the color of the text for a specific row (= 3 cells). Unfortunately, this code doesn't work:

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

Any input would be appreciated.

도움이 되었습니까?

해결책

There's actually a very simple solution:

  1. Attach an event handler:

    EventLogGrid.RowLoaded += EventLogGrid_RowLoaded;
    
  2. Change the color of the row:

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

다른 팁

Try something like this also Telerik website has tons of awesome examples 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;
        }
    }
}

or this can work for you I've tested this and it work make sure to replace the name of the Columns with your Column Name if you give me the column name, since you have 3 Columns I would need the Fist Column name.. hope this makes sense for you

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 ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top