Reputation: 904
I am trying to figure out how to add a background color to both the first row and all of the cells in the first column in my RadGrid.
Upvotes: 0
Views: 1211
Reputation: 355
You can also use cell formatting event.
void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
if (e.CellElement.ColumnInfo is GridViewDataColumn)
{
if (((GridViewDataColumn)e.CellElement.ColumnInfo).FieldName == "City")
{
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = System.Drawing.Color.Beige;
}
}
}
Upvotes: 1
Reputation: 904
To add a background color to any specific column simply set the ItemStyle-BackColor property of the column:
ItemStyle-BackColor="LightGrey"
To add a background color to the first row you can do this in the grid's PreRender event:
protected void grid_PreRender(object sender, EventArgs e)
{
if (grid.Items.Count > 0)
{
//Format first row of grid
grid.Items[0].BackColor = Color.LightGray;
}
}
Upvotes: 1