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

Grouping Rows in a DataGrid

By , 26 Apr 2005
Rate this:
Please Sign up or sign in to vote.

Introduction

This is built off the same idea that Serge Lobko-Lobanovsky had in his article on here at http://www.codeproject.com/aspnet/GridGroupFormat.asp.

had trouble with the code he had posted and had to get it done for a project. Just call the method DataGridGroupBy(DataGrid dgYouWantGrouped, int ColumnToGroup) of the DataGridGroupByRows class in your WebForm and it will group all rows you want grouped together.

Here is the code for a class i wrote in the sample project attached:

using System;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace localhost
{
/// <span class="code-SummaryComment"><SUMMARY>
</span>/// Summary description for DataGridGrouper.
/// <span class="code-SummaryComment"></SUMMARY>
</span>public class DataGridGrouper
{
    public DataGridGrouper()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public void GroupColumn(DataGrid dgMonitor, int ColumnIndex)
    {
        int ItemIndex= 0;

        foreach(DataGridItem dgItem in dgMonitor.Items)
        {
            if(dgItem.ItemIndex >

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

BriOnH
Web Developer
United States United States
Web Programmer / Analyst for Integres.com, and part owner www.golfbagstore.com

Comments and Discussions

 
GeneralMy vote of 1 PinmemberHristo Bojilov27-Aug-09 4:53 
GeneralLast row in datagrid does not group [modified] PinsussJohn hazin10-Dec-07 4:58 
GeneralRe:Grouping Rows in a DataGrid PinmemberVolcano__12-May-07 6:46 
GeneralFixed and understandible Pinmembermgrisoli8-Jan-07 6:18 
GeneralLast Row Problem solved .. [modified] PinmemberVMSSanthosh20-Sep-06 19:39 
GeneralThank you! PinmemberShivam Ray16-Aug-06 13:42 
GeneralMy implementation with stylesheet support Pinmemberkoedoot15-Mar-06 0:04 
QuestionWhat&#180;s going on with the las row? PinmemberFrancisko20-Jul-05 9:24 
AnswerRe: What&amp;#180;s going on with the las row? PinmemberSpithas2-Nov-05 22:39 
AnswerRe: What's going on with the last row? PinmemberRoyPardee5-Jul-06 11:22 
GeneralRe: What's going on with the last row? Pinmembermgrisoli8-Jan-07 6:16 

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 | Mobile
Web01 | 2.8.140421.2 | Last Updated 26 Apr 2005
Article Copyright 2004 by BriOnH
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid