Click here to Skip to main content
13,457,971 members
Click here to Skip to main content


134 bookmarked
Posted 27 Sep 2010

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.Linq;
using System.Web;
using System.Data;
using System.Data.OleDb;

// Written by Anurag Gandhi.
// Url:
// Contact me at:

/// <summary>
/// Summary description for ExcelLayer
/// </summary>
public class ExcelLayer
	public ExcelLayer()
		// TODO: Add constructor logic here
    /// <summary>
    /// Retireves the data from Excel Sheet to a DataTable.
    /// </summary>
    /// <param name="FileName">File Name along with path from the root folder.</param>
    /// <param name="TableName">Name of the Table of the Excel Sheet. Sheet1$ if no table.</param>
    /// <returns></returns>
    public static DataTable GetDataTable(string FileName, string TableName, string SortColumn)
            string strPath = HttpContext.Current.Request.PhysicalApplicationPath + FileName;
            DataSet ds = new DataSet();
            String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; " + "Data Source=" + strPath + "; " + "Extended Properties=Excel 8.0;";

            OleDbConnection objConn = new OleDbConnection(sConnectionString);

            string Query = "SELECT * FROM [" + TableName + "] where IsActive = 1";
            if (SortColumn != "")
                Query += " order by " + SortColumn;

            OleDbCommand objCmdSelect = new OleDbCommand(Query, objConn);
            OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
            objAdapter1.SelectCommand = objCmdSelect;
            return ds.Tables[0];
        catch (Exception ex)
            //Log your exception here.//
            return (DataTable)null;

    public static DataTable GetDataTable(string FileName, string TableName)
        return GetDataTable(FileName, TableName, String.Empty);

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, and a Speaker. 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.
He can be contacted at:

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02-2016 | 2.8.180323.1 | Last Updated 22 Aug 2014
Article Copyright 2010 by Anurag Gandhi
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid