Click here to Skip to main content
Licence 
First Posted 14 Dec 2003
Views 162,889
Downloads 2,424
Bookmarked 46 times

Simple DataGrid grouping

By | 14 Dec 2003 | Article
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

About the Author

Serge Lobko-Lobanovsky

Web Developer

Belarus Belarus

Member

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


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 Pinmembermanoj kumar choubey19:29 7 Feb '12  
GeneralMerging row in Template column [modified] Pinmembersarika tyagi16:45 7 Sep '08  
QuestionHi Can i get the same code in C# for databound column. Plz help Pinmemberharsha123453:42 7 Jul '08  
GeneralHelp me peleas Pinmemberjuan e tobias12:51 9 Jun '08  
GeneralMerging fails with AutoGenerated columns PinmemberFrancois Grobler22:52 6 Dec '06  
GeneralIsGroupedCol Pinmemberamit singla22:08 6 Dec '06  
GeneralRe: IsGroupedCol PinmemberFrancois Grobler22:50 6 Dec '06  
QuestionIsGroupedCol still missing Pinmemberr.desjardins5:31 19 May '06  
AnswerRe: IsGroupedCol still missing PinmemberFrancois Grobler22:47 6 Dec '06  
Questionmissing IsGroupedCol function Pinmemberdinnu19745:50 23 Mar '06  
QuestionHow could I use the class from my aspx? Pinmemberlprado4:50 31 Jan '06  
GeneralWhy noone is interested in enhancing WinDatagrid PinmemberFaiNg20:45 22 Nov '05  
QuestionWindows data grid PinmemberMukund Pujari2:23 5 Sep '05  
AnswerRe: Windows data grid Pinmemberarilou2:29 5 Sep '05  
QuestionTrace not declared - any resolution? PinmemberCliffGilbert22:59 3 Aug '05  
AnswerRe: Trace not declared - any resolution? Pinmemberarilou23:11 3 Aug '05  
GeneralRe: Trace not declared - any resolution? PinmemberCliffGilbert23:29 3 Aug '05  
Generalexcellent Pinmemberpragaw4:07 26 May '05  
GeneralThanks PinmemberAlbai Adrian3:04 26 Apr '05  
GeneralError in Trace Pinmemberyolimap10:38 15 Feb '05  
GeneralError in Trace Pinmemberyolimap10:35 15 Feb '05  
GeneralMissing IsGroupedCol Function PinmemberRaj Aryan22:27 11 Jan '05  
GeneralRe: Missing IsGroupedCol Function Pinmemberbrcordova12:42 14 Feb '05  
GeneralRe: Missing IsGroupedCol Function Pinmemberyolimap10:59 15 Feb '05  
GeneralRe: Missing IsGroupedCol Function Pinmemberbrcordova12:00 15 Feb '05  

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.

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