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

Advertisements

2 thoughts on “How to set different color for each Group Header in WebGrid

  1. Kegiampidague

    Excellent site intersoftpt.wordpress.com and I am really pleased to see you have what I am actually looking for here: this .. as it’s taken me literally 2 hours and 50 minutes of searching the web to find you (just kidding!) so I shall be pleased to become a regular visitor 🙂

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s