Click here to Skip to main content
14,147,016 members
Click here to Skip to main content


135 bookmarked
Posted 27 Sep 2010
Licenced CPOL

Group GridView Data

, 22 Aug 2014
A custom GridView control which provides you an additional facility to group the data in gridview along with the facility to customise the Group Header and Group Footer
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="GroupGridViewCtrl" Namespace="GroupGridViewCtrl" TagPrefix="gsoft" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <title>Grouping GridView Demo</title>
    <link media="all" href="css/StyleSheet.css" rel="Stylesheet" type="text/css" />
    <script type="text/javascript" language="javascript" src="js/jquery-1.4.2.min.js"></script>
    <form id="form1" runat="server">
        Group GridView Data Using Custom Control
    <div style="width:800px;">
            Here, this page allows you to choose the column which you wish to Group and set the animation speed for fading In and Out.
        <table style="width:100%;">
                <td align="left">
                    Group Column: <asp:DropDownList ID="ddlGroupColumn" runat="server" AutoPostBack="true" Width="150" 
                <td align="right">
                    Animation Speed: <asp:DropDownList ID="ddlAnimationSpeed" runat="server"  AutoPostBack="true"
                        Width="150" OnSelectedIndexChanged="ddlAnimationSpeed_SelectedIndexChanged"></asp:DropDownList>
        <gsoft:GroupGridView AllowGrouping="true" GroupColumnName="Year" ID="grdRawData" runat="server" BackColor="White" AutoGenerateColumns="false"
            BorderColor="#cEcFcE" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" CellSpacing="2" Width="800"
                <div style="background-color:#ccddff;">
                    <table style="width:100%;">
                            <td style="width:50%; font-weight:bold;"><%# Container.GroupColumnName + ": " + Container.GroupColumnData.ToString() %> </td>
                            <td style="width:50%;">Total Students: <%# Container.Count("Name") %></td>
                            <td>Average Marks: <%# Math.Round((decimal)Container.Average("Marks"), 2) %></td>
                            <td>Highest: <%# Container.Max("Marks") %></td>
                            <td colspan="2">Topper: <%# Container.GetValue("Name", "Marks", Container.Max("Marks").ToString())%></td>
                <div style="background-color:#fcddcf; text-align:center;">
                    This is Footer of <%# Container.GroupColumnName + ": " + Container.GroupColumnData.ToString() %>.
                <asp:TemplateField HeaderText="S. No.">
                        <%# Container.DataItemIndex + 1 %>.
                <asp:BoundField HeaderText="Name" DataField="Name" />
                <asp:BoundField HeaderText="Branch" DataField="Branch" />
                <asp:BoundField HeaderText="Year" DataField="Year" />
                <asp:BoundField HeaderText="Marks" DataField="Marks" />
                <asp:BoundField HeaderText="Gender" DataField="Gender" />
                <asp:BoundField HeaderText="College" DataField="College" />
            <RowStyle BackColor="#FFFFFF" />
            <FooterStyle BackColor="#CCCC99" />
            <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#5B598B" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="#e8e8ff" />

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Anurag Gandhi
India India
Anurag Gandhi is a Developer, Consultant, Architect, Blogger, Speaker and a Microsoft Employee. He is passionate about programming.
He is extensively involved in Asp.Net Core, MVC/Web API, Microsoft Azure/Cloud, web application hosting/architecture, Angular, AngularJs, design and development. His languages of choice are C#, Node/Express, JavaScript, Asp .NET MVC, Asp, C, C++. He is familiar with many other programming languages as well. He mostly works with MS Sql Server as the preferred database and has worked with Redis, MySQL, Oracle, MS Access, etc. also.
He is active in programming communities and loves to share the knowledge with others whenever he gets the time for it.
He is also a passionate chess player.
Linked in Profile:
He can be contacted at:

Disclaimer: Any posts, article, content present in this website is my personal opinion based on best of my knowledge and experience. None of the content provided by me should be considered as official communication/opinion or my Employer.

You may also be interested in...

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190518.1 | Last Updated 22 Aug 2014
Article Copyright 2010 by Anurag Gandhi
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid