Click here to Skip to main content
Click here to Skip to main content

Simple DataGrid grouping

, 14 Dec 2003
Rate this:
Please Sign up or sign in to vote.
The given class provides a simple way of grouping DataGrid rows as it is done in MS FlexGrid ActiveX control.

Sample Image - Preview.jpg


Everybody knows that a DataGrid is a very useful control that is available in ASP.NET. It has many built-in features, such as sorting, paging, etc. However, one useful thing is lacking – the ability to merge cells like it is implemented in MS FlexGrid ActiveX control. In one of my projects, I came across this need and decided to implement it.

Designing a web control is claimed to be an easy thing, but my choice was to develop a reusable class. How to do it?

The Code Itself

There is a well-known ability in .NET framework – binding events to user-defined procedures. In VB.NET, it is achieved by using AddHandler routine. Upon my class initialization, GroupGridItem is bound to the ItemDataBound event of the DataGrid control.

So, every time ItemDataBound event is raised, the control passes to GroupGridItem method of the class. It is here that all the stuff takes place. The algorithm is pretty simple: for each bound item, it searches previously bound ones and if the content of the respective cells match, it hides current cell and increases the previous visible cell RowSpan value by one.

The use of the class is simple – just pass the DataGrid to format and the column indices you'd like to see grouped.

This is only a first version of the class, so it supports only Bound columns. Your comments will be really appreciated.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Serge Lobko-Lobanovsky
Web Developer
Belarus Belarus
I work for Logic Software ( as a lead .NET developer/architect.

Comments and Discussions

GeneralMy vote of 5 Pinmembermanoj kumar choubey7-Feb-12 20:29 
GeneralMerging row in Template column [modified] Pinmembersarika tyagi7-Sep-08 17:45 
QuestionHi Can i get the same code in C# for databound column. Plz help Pinmemberharsha123457-Jul-08 4:42 
GeneralHelp me peleas Pinmemberjuan e tobias9-Jun-08 13:51 
GeneralMerging fails with AutoGenerated columns PinmemberFrancois Grobler6-Dec-06 23:52 
GeneralIsGroupedCol Pinmemberamit singla6-Dec-06 23:08 
GeneralRe: IsGroupedCol PinmemberFrancois Grobler6-Dec-06 23:50 
QuestionIsGroupedCol still missing Pinmemberr.desjardins19-May-06 6:31 
AnswerRe: IsGroupedCol still missing PinmemberFrancois Grobler6-Dec-06 23:47 
Questionmissing IsGroupedCol function Pinmemberdinnu197423-Mar-06 6:50 
QuestionHow could I use the class from my aspx? Pinmemberlprado31-Jan-06 5:50 
GeneralWhy noone is interested in enhancing WinDatagrid PinmemberFaiNg22-Nov-05 21:45 
QuestionWindows data grid PinmemberMukund Pujari5-Sep-05 3:23 
AnswerRe: Windows data grid Pinmemberarilou5-Sep-05 3:29 
QuestionTrace not declared - any resolution? PinmemberCliffGilbert3-Aug-05 23:59 
AnswerRe: Trace not declared - any resolution? Pinmemberarilou4-Aug-05 0:11 
GeneralRe: Trace not declared - any resolution? PinmemberCliffGilbert4-Aug-05 0:29 
Generalexcellent Pinmemberpragaw26-May-05 5:07 
GeneralThanks PinmemberAlbai Adrian26-Apr-05 4:04 
GeneralError in Trace Pinmemberyolimap15-Feb-05 11:38 
GeneralError in Trace Pinmemberyolimap15-Feb-05 11:35 
GeneralMissing IsGroupedCol Function PinmemberRaj Aryan11-Jan-05 23:27 
GeneralRe: Missing IsGroupedCol Function Pinmemberbrcordova14-Feb-05 13:42 
GeneralRe: Missing IsGroupedCol Function Pinmemberyolimap15-Feb-05 11:59 
GeneralRe: Missing IsGroupedCol Function Pinmemberbrcordova15-Feb-05 13:00 
GeneralRe: Missing IsGroupedCol Function Pinsussrcarpin15-Apr-05 3:48 
GeneralRe: Missing IsGroupedCol Function Pinmemberbrcordova15-Apr-05 7:09 
GeneralRe: Missing IsGroupedCol Function Pinsussrcarpin15-Apr-05 9:50 
GeneralGood Work PinmemberHemang Shukla22-Sep-04 14:11 
GeneralA little tweak! Pinsussbarsju30-Jul-04 3:20 
GeneralRe: A little tweak! PinmemberSerge Lobko-Lobanovsky30-Jul-04 3:30 
GeneralAlign Text in grouped Cell Pinmemberruuca3-Jul-04 2:26 
Generalmissing Isgroupcol function Pinsussbrijesh_Pandya17-Jun-04 6:27 
GeneralRe: missing Isgroupcol function PinmemberSerge Lobko-Lobanovsky17-Jun-04 6:34 
GeneralGood Job.. Pinmembernickpatel1-Apr-04 11:35 
GeneralGood Idea. Pinmemberflorkflork25-Dec-03 8:32 
GeneralA sample file would help. PinmemberCypher17-Dec-03 23:20 
GeneralRe: A sample file would help. PinmemberSerge Lobko-Lobanovsky17-Dec-03 23:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141216.1 | Last Updated 15 Dec 2003
Article Copyright 2003 by Serge Lobko-Lobanovsky
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid