Reputation: 2012
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.
Upvotes: 4
Views: 6104
Reputation: 488
There's actually a very simple solution:
Attach an event handler:
EventLogGrid.RowLoaded += EventLogGrid_RowLoaded;
Change the color of the row:
if (((EventLogRow)e.DataElement).MsgType == EventLogger.EventType.Exception)
{
e.Row.Foreground = new SolidColorBrush(Colors.Red);
}
Upvotes: 4
Reputation: 18863
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;
}
}
Upvotes: 1