Net-informations.com
SiteMap  | About    

Gridview export to Excel



In Asp.Net, we can export the data in the Gridview control to an Excel file. Here we are going to bind the data in GridView at runtime and we create a button to allow user to export the dtata to an Excel file. In the previous lesson we saw how to bind a Gridview at runtime.

GridView at Runtime

Database

In this article I have used Microsoft's Pubs database for sample data. You can download it free from the following link.

Download

Drag and Drop one GridView control and a Button control to the defailt.aspx file. In the code behind, write the code for connecting database in the page_load event and in the Button click event write the code for export to excel file.

export gridview to excel

After export to excel file, when you open the excel file, it look like the following :

gridview to excel

Default.aspx

C# Source Code

VB.NET Source Code








net-informations.com (C) 2019    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.