C#.Net – Programmatically Group Gridview Column Headers in ASP.Net,VB.Net

In this tutorial i am going to explain about how to programmatically group gridview column headers to give specific titles to the columns.

In my previous article i have explained about How To Convert JSON Data Into Html Table Using Javascript jQuery, Upload multiple files in asp.net C#.Net VB.Net / Maximum Request Length Exceeded, Change Row Color of a Grid view Based on Particular Condition C#.Net ASP.Net VB.Net, Fill Datatable and Bind GridView Using Data Reader in ASP.Net C#.Net VB.Net, how to get the selected values from checkboxlist in C#.Net and VB.Net, how to implement option group in asp.net drop down list, ASP.Net – Bind Array To DropDownList in C#.Net,VB.Net.


Grouping grid view column headers is achieved using on OnRowCreated even of the grid view.

For explanation purpose i have created a new empty asp.net website and added default.aspx file into the website. Inside the webform i have dragged grid view control from the toolbox and added to the web form and added the columns that i would like to display as the bound field with the headertext. I have mentioned some styles that can be used to render the grid view.

HTML Markup:

I code behind file i have created a datatable and created some columns in that datatable to insert employee records. Once the table is created i have inserted the sample records and then binded that datatable to gridview. On OnRowCreated event of the grid view the master header that is the columns are grouped and master header is added. Below is the code.

C#.Net

VB.Net:

The output will look like below

Output of C#.Net - Programmatically Group Gridview Column Headers in ASP.Net,VB.Net

You may also like:

  1. ASP.Net – Validate form using css in C#.Net
  2. How to change Placeholder text color on focus using css
  3. How to change placeholder text color
  4. ASP.Net – Bind Array To DropDownList in C#.Net,VB.Net
  5. Code to encrypt and decrypt files using C#.Net, ASP.Net
  6. Binding Gridview in Asp.net
  7. C# code to bind XML data to Grid view
  8. Change Row Color of a Grid view Based on Particular Condition C#.Net ASP.Net VB.Net 
  9. How to show confirm message while deleting grid view row.
  10. Select deselect all checkboxes in grid view using javascript

Sourcecode of programmatically grouping gridview column header in C#.Net VB.Net

Download sourcecode of Programmatically Group Gridview Column Headers in ASP.Net,VB.Net


Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!