Tag Archives: GroupHeader

How to set different color for each Group Header in WebGrid

Hi All,

Few weeks ago I got interesting inquiry from one of our customers, about how to set different color for each group header in WebGrid, and I think that it’s an interesting topics to be post on our corporate blogs.

Ok, first of all you need to bind your Webgrid and at the code behind inside WebGrid1_InitializeRow event, you can add the following code:

protected void WebGrid1_InitializeRow(object sender, ISNet.WebUI.WebGrid.RowEventArgs e)
{
        if (e.Row.Type == ISNet.WebUI.WebGrid.RowType.GroupHeader) 
       {
             if (e.Row.Cells.GetNamedItem("your column name").Text == "the content of your cell")        
                 e.Row.Style.BackColor = Color.Red;
             else
                 e.Row.Style.BackColor = Color.Yellow;
       }
}

For more information, you can download the sample here. The sample used Northwind.mdb and the WebGrid bind to AccessDataSource.

If you have questions regarding this solution, please don’t hesitate to post the question in here.

Cheers,

Gordon Tumewu