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


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


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


C# Source Code

VB.NET Source Code (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About