Click here to Skip to main content
15,885,435 members
Articles / Web Development / ASP.NET

Export large data from a GridView and DataReader to an Excel file using C#

Rate me:
Please Sign up or sign in to vote.
4.60/5 (10 votes)
20 Jun 2007CPOL4 min read 98.5K   687   41  
An article on exporting large data to excel file
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Export data to excel</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <br />
    <asp:GridView ID="grdStudentMarks"  Font-Names="verdana" runat="server" DataSourceID="dsStudentMarks">
        <EmptyDataTemplate>
            No Data Found
        </EmptyDataTemplate>
        <RowStyle BackColor="white" />
        <AlternatingRowStyle BackColor="beige" />
        <HeaderStyle CssClass="ClsHeaderRow" />               
    </asp:GridView>
    <asp:SqlDataSource ID="dsStudentMarks" runat="server" ConnectionString="Data Source=.;Initial Catalog=UniversityManager;Integrated Security=True;"
        SelectCommand="
                (
                SELECT *FROM STUDENT                                     
	            )                 
                ">        
    </asp:SqlDataSource>
        &nbsp;<br />
    <asp:Button ID="btnExportFromDatagrid" runat="server" Text="Export From Grid"        OnClick="btnExportFromDatagrid_Click" />
    <asp:Button ID="btnExportFromDataset"  runat="server" Text="Export From Data Reader" OnClick="btnExportFromDataset_Click" />
    </div>
    </form>
</body>
</html>

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)


Written By
Software Developer (Senior) Nascenia Ltd. (www.nascenia.com)
Bangladesh Bangladesh
Fuad Bin Omar is co-founder and COO of Nascenia Ltd . () Prior to joining in Nascenia he worked as a "Senior Software Engineer" at the offshore development office of Code71,Inc
Fuad have more than five years of experience in developing business applications using .NET and Ruby on Rails technologies.


He is an MBA in the Department of Finance at University of Dhaka, Bangladesh .
He is a Computer Science and Engineering graduate from Khulna University of Engineering & Technology (KUET), Bangladesh.

His articles published in the codeproject:

Multi-color DropDownList using C#

Export large data from Gridview and Datareader to an Excel file using C#

Mailto Fuad at fuadcse@yahoo.com

Comments and Discussions