Hire my services

If you would like to hire my services, you can now do so by visiting the following link:

Website Design Darlington

Article Statistics

ArticlesLatest Entry
2121-May-2008

Code Bank Statistics

CategoryTipsLatest Entry
Applications420-Feb-2008
Cache118-Apr-2007
Controls926-Jul-2007
CSS107-Sep-2007
Database428-Aug-2007
Dates128-Aug-2007
Email105-Mar-2007
Files123-Apr-2007
HTML101-Mar-2007
Images226-Mar-2007
Pages115-Oct-2007
Sessions122-Nov-2007
SQL Server1518-Mar-2008
Strings309-May-2007
Skip Navigation LinksHome > Articles > How to export a GridView to Excel

How to export a GridView to Excel

Summary: A simple look at how you can easily add "Export To Excel" functionality to your GridView.Socialize it

Data that is shown to users in a GridView can be very useful, however, there are times when a user needs to save this information to a more permanent state, or they need to do some manipulation to it. This is where an "Export To Excel" feature would come in handy. Luckily for us, it's fairly easy to accomplish and you don't need to change the way you populated your GridView originally.

Let's start by creating a simple page with just a GridView and a Button on it:

Now, we need to:

1) Populate the GridView
2) Add the code to export the data to excel

Here's how this is done:

As you'll see from above, we populate the GridView on the Page Load event with some sample data and the Button1.Click method handles the export to excel.

Hopefully the comments in the code are fairly self-explanatory so I won't have to explain the process here. The only thing that may be confusing is the empty "VerifyRenderingInServerForm" procedure. The only reason this is included is without it, the ASP.NET Page will complain about the GridView not being inside form tags. By overriding this method, we get rid of the error.

Reader Comments

1. Marco 13/04/2007 06:24:59

2. Helge 26/04/2007 02:42:10

3. Dimitar Voynov 07/06/2007 00:32:30

4. John 12/07/2007 07:28:45

5. Mark Smith 14/07/2007 04:31:57

6. John 02/11/2007 09:13:42

7. Gau 08/01/2008 00:00:36

8. Jet 03/04/2008 05:14:18

9. Pawan Gupta 17/06/2008 02:56:18

Add your comments

Please keep your comments relevant to this page. Any inappropriate or purely promotional comments may be removed. Email addresses are never displayed but are required so you can confirm your comments.

Your Name:
 
Your Email:
 
Add your comments: