Click here to Skip to main content
15,886,873 members
Articles / Web Development / ASP.NET
Article

Simple DataGrid grouping

Rate me:
Please Sign up or sign in to vote.
3.16/5 (34 votes)
14 Dec 20031 min read 219.5K   3.4K   46   38
The given class provides a simple way of grouping DataGrid rows as it is done in MS FlexGrid ActiveX control.

Sample Image - Preview.jpg

Introduction

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.

License

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


Written By
Web Developer
Belarus Belarus
I work for Logic Software (http://www.logicsoftware.net) as a lead .NET developer/architect.

Comments and Discussions

 
GeneralRe: Missing IsGroupedCol Function Pin
Ricardo Ostos15-Apr-05 6:09
Ricardo Ostos15-Apr-05 6:09 
GeneralRe: Missing IsGroupedCol Function Pin
rcarpin15-Apr-05 8:50
rcarpin15-Apr-05 8:50 
GeneralGood Work Pin
Hemang Shukla22-Sep-04 13:11
Hemang Shukla22-Sep-04 13:11 
GeneralA little tweak! Pin
barsju30-Jul-04 2:20
barsju30-Jul-04 2:20 
GeneralRe: A little tweak! Pin
Serge Lobko-Lobanovsky30-Jul-04 2:30
Serge Lobko-Lobanovsky30-Jul-04 2:30 
GeneralAlign Text in grouped Cell Pin
Member 6479613-Jul-04 1:26
Member 6479613-Jul-04 1:26 
Generalmissing Isgroupcol function Pin
brijesh_Pandya17-Jun-04 5:27
sussbrijesh_Pandya17-Jun-04 5:27 
GeneralRe: missing Isgroupcol function Pin
Serge Lobko-Lobanovsky17-Jun-04 5:34
Serge Lobko-Lobanovsky17-Jun-04 5:34 
Hi,

Thanks for interest in this article Smile | :)

See the previous post in the forum for the article for the needed function Smile | :)

Cheers,

Regards,
Serge (Logic Software, Easy Projects .NET site)
GeneralGood Job.. Pin
nickpatel1-Apr-04 10:35
nickpatel1-Apr-04 10:35 
GeneralGood Idea. Pin
Chabun25-Dec-03 7:32
Chabun25-Dec-03 7:32 
GeneralA sample file would help. Pin
Cypher17-Dec-03 22:20
Cypher17-Dec-03 22:20 
GeneralRe: A sample file would help. Pin
Serge Lobko-Lobanovsky17-Dec-03 22:41
Serge Lobko-Lobanovsky17-Dec-03 22:41 

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

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