Click here to Skip to main content
11,644,284 members (65,438 online)
Click here to Skip to main content

Simple DataGrid grouping

, 14 Dec 2003 181.2K 3.1K 47
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

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

Share

About the Author

Serge Lobko-Lobanovsky
Web Developer
Belarus Belarus
I work for Logic Software (http://www.logicsoftware.net) as a lead .NET developer/architect.

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 5 Pin
manoj kumar choubey7-Feb-12 19:29
membermanoj kumar choubey7-Feb-12 19:29 
GeneralMerging row in Template column [modified] Pin
sarika tyagi7-Sep-08 16:45
membersarika tyagi7-Sep-08 16:45 
QuestionHi Can i get the same code in C# for databound column. Plz help Pin
harsha123457-Jul-08 3:42
memberharsha123457-Jul-08 3:42 
GeneralHelp me peleas Pin
juan e tobias9-Jun-08 12:51
memberjuan e tobias9-Jun-08 12:51 
GeneralMerging fails with AutoGenerated columns Pin
Francois Grobler6-Dec-06 22:52
memberFrancois Grobler6-Dec-06 22:52 
GeneralIsGroupedCol Pin
amit singla6-Dec-06 22:08
memberamit singla6-Dec-06 22:08 
GeneralRe: IsGroupedCol Pin
Francois Grobler6-Dec-06 22:50
memberFrancois Grobler6-Dec-06 22:50 
QuestionIsGroupedCol still missing Pin
r.desjardins19-May-06 5:31
memberr.desjardins19-May-06 5:31 
AnswerRe: IsGroupedCol still missing Pin
Francois Grobler6-Dec-06 22:47
memberFrancois Grobler6-Dec-06 22:47 
Questionmissing IsGroupedCol function Pin
dinnu197423-Mar-06 5:50
memberdinnu197423-Mar-06 5:50 
QuestionHow could I use the class from my aspx? Pin
lprado31-Jan-06 4:50
memberlprado31-Jan-06 4:50 
GeneralWhy noone is interested in enhancing WinDatagrid Pin
FaiNg22-Nov-05 20:45
memberFaiNg22-Nov-05 20:45 
QuestionWindows data grid Pin
Mukund Pujari5-Sep-05 2:23
memberMukund Pujari5-Sep-05 2:23 
AnswerRe: Windows data grid Pin
arilou5-Sep-05 2:29
memberarilou5-Sep-05 2:29 
QuestionTrace not declared - any resolution? Pin
CliffGilbert3-Aug-05 22:59
memberCliffGilbert3-Aug-05 22:59 
AnswerRe: Trace not declared - any resolution? Pin
arilou3-Aug-05 23:11
memberarilou3-Aug-05 23:11 
GeneralRe: Trace not declared - any resolution? Pin
CliffGilbert3-Aug-05 23:29
memberCliffGilbert3-Aug-05 23:29 
Generalexcellent Pin
pragaw26-May-05 4:07
memberpragaw26-May-05 4:07 
GeneralThanks Pin
Albai Adrian26-Apr-05 3:04
memberAlbai Adrian26-Apr-05 3:04 
GeneralError in Trace Pin
yolimap15-Feb-05 10:38
memberyolimap15-Feb-05 10:38 
GeneralError in Trace Pin
yolimap15-Feb-05 10:35
memberyolimap15-Feb-05 10:35 
GeneralMissing IsGroupedCol Function Pin
Raj Aryan11-Jan-05 22:27
memberRaj Aryan11-Jan-05 22:27 
GeneralRe: Missing IsGroupedCol Function Pin
brcordova14-Feb-05 12:42
memberbrcordova14-Feb-05 12:42 
GeneralRe: Missing IsGroupedCol Function Pin
yolimap15-Feb-05 10:59
memberyolimap15-Feb-05 10:59 
GeneralRe: Missing IsGroupedCol Function Pin
brcordova15-Feb-05 12:00
memberbrcordova15-Feb-05 12:00 
GeneralRe: Missing IsGroupedCol Function Pin
rcarpin15-Apr-05 2:48
sussrcarpin15-Apr-05 2:48 
GeneralRe: Missing IsGroupedCol Function Pin
brcordova15-Apr-05 6:09
memberbrcordova15-Apr-05 6:09 
GeneralRe: Missing IsGroupedCol Function Pin
rcarpin15-Apr-05 8:50
sussrcarpin15-Apr-05 8:50 
GeneralGood Work Pin
Hemang Shukla22-Sep-04 13:11
memberHemang Shukla22-Sep-04 13:11 
GeneralA little tweak! Pin
barsju30-Jul-04 2:20
sussbarsju30-Jul-04 2:20 
GeneralRe: A little tweak! Pin
Serge Lobko-Lobanovsky30-Jul-04 2:30
memberSerge Lobko-Lobanovsky30-Jul-04 2:30 
GeneralAlign Text in grouped Cell Pin
ruuca3-Jul-04 1:26
memberruuca3-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
memberSerge Lobko-Lobanovsky17-Jun-04 5:34 
GeneralGood Job.. Pin
nickpatel1-Apr-04 10:35
membernickpatel1-Apr-04 10:35 
GeneralGood Idea. Pin
florkflork25-Dec-03 7:32
memberflorkflork25-Dec-03 7:32 
GeneralA sample file would help. Pin
Cypher17-Dec-03 22:20
memberCypher17-Dec-03 22:20 
GeneralRe: A sample file would help. Pin
Serge Lobko-Lobanovsky17-Dec-03 22:41
memberSerge Lobko-Lobanovsky17-Dec-03 22: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
Web02 | 2.8.150731.1 | Last Updated 15 Dec 2003
Article Copyright 2003 by Serge Lobko-Lobanovsky
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid