Click here to Skip to main content
14,108,747 members
Click here to Skip to main content

Stats

199.7K views
11.6K downloads
134 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
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MultipleGrid : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindDropDownList();
            BindGridView(grdRawData.GroupColumnName + ", Name");
            BindEmployeeGrid(grdEmployee.GroupColumnName + ", Name");
        }
    }

    //Binds the Data in GridView used in the page.//
    private void BindGridView(string SortColumn)
    {
        // Retrieve the data table from Excel Data Source.//
        DataTable dt = ExcelLayer.GetDataTable(GlobalData.DataSource.FileName, GlobalData.DataSource.TableName, SortColumn);

        grdRawData.DataSource = dt;
        grdRawData.DataBind();
    }

    //Binds the Data in GridView used in the page.//
    private void BindEmployeeGrid(string SortColumn)
    {
        // Retrieve the data table from Excel Data Source.//
        DataTable dt = ExcelLayer.GetDataTable("_Data\\Employee.xls", GlobalData.DataSource.TableName, SortColumn);

        grdEmployee.DataSource = dt;
        grdEmployee.DataBind();
    }

    /// <summary>
    /// Binds the Data in DropDownList used in the page.//
    /// </summary>
    private void BindDropDownList()
    {
        ddlGroupColumn.DataSource = GlobalData.GetGroupColumns();
        ddlGroupColumn.DataTextField = "Value";
        ddlGroupColumn.DataValueField = "Key";
        ddlGroupColumn.DataBind();

        ddlAnimationSpeed.DataSource = Enum.GetNames(typeof(GroupGridViewCtrl.Animation));
        ddlAnimationSpeed.DataBind();
    }

    /// <summary>
    /// Event Handler for Group Column.//
    /// </summary>
    /// <param name="sender">sender control</param>
    /// <param name="e">Event Args</param>
    protected void ddlGroupColumn_SelectedIndexChanged(object sender, EventArgs e)
    {
        string ColumnName = ddlGroupColumn.SelectedValue;
        grdRawData.GroupColumnName = ColumnName;
        BindGridView(ColumnName + ", Name");
    }

    /// <summary>
    /// Event Handler for Animation Speed.//
    /// </summary>
    /// <param name="sender">sender control</param>
    /// <param name="e">Event Args</param>
    protected void ddlAnimationSpeed_SelectedIndexChanged(object sender, EventArgs e)
    {
        GroupGridViewCtrl.Animation SelectedAnimation = (GroupGridViewCtrl.Animation)Enum.Parse(typeof(GroupGridViewCtrl.Animation), ddlAnimationSpeed.SelectedValue);
        grdRawData.AnimationSpeed = SelectedAnimation;
        grdRawData.GroupColumnName = ddlGroupColumn.SelectedValue;
        BindGridView(ddlGroupColumn.SelectedValue + ", Name");
    }
}

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.

License

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

Share

About the Author

Anurag Gandhi
Architect
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: https://in.linkedin.com/in/anuraggandhi
He can be contacted at: soft.gandhi@gmail.com

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
Web03 | 2.8.190518.1 | Last Updated 22 Aug 2014
Article Copyright 2010 by Anurag Gandhi
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid