Friday, 9 April 2010

ASP.NET: How to Group Data in the GridView Control

One of my clients was not happy with a GridView control that repeated a category name next to every product inside that category. He asked if we could group the table to display the category name only once rather than displaying it for every product, e.g. something like:


'Crap', I thought. 'This doesn't come easily to the GridView control.'

But after some research into several different methods, I found a good one that worked well for me. It was created by a developer called 'dotNetSoldier', and the control is called the ZNet Extended GridView.

You just download the DLL file and drop it into your bin folder, add the control to your Toolbox and drag it onto your page. Then follow the instructions on his blog to get started.

I'd rather not have had to add another reference in my project or use a third party control, but I couldn't get the traditional GridView to behave in this way.

2 comments:

Anonymous said...

Nice information. Keep it up!

Phil said...

It's worth looking at the ListView control in this context, since it has a lot more granular control of rendering than the GridView and comes with grouping functionality by default.