Nezir Zahirović

Fast export of AspxGridView data to Excel ,PDF ,CSV ,RTF file type C#,VB.NET

Hi to all of you who came in this place searching some info about programming . In this blog post I will show you how to do very, I mean very fast export of Your data from AspxGridView to Excel spreadsheet ( or PDF or CSV or RTF file type ).
First of all in this post I will use DevExpress controls toolkit (8.2.4). That's mean DevExpress toolkit is requirement.
You can find 60 days trial version on this link:
Let's start with show J
First we need to start our Visual Studio 2008 ( my favorite version, but this version of DevExpres controls works fine with VS2005 ).
As we start new Web Site Project template, we need to find our AspxGridView control on VS Toolbox and do simple drag & drop on our test page.
Next step ,we need to do simple connection between aspxgridview and sqldatasource, I hope you all know how to do that J.

After we successfully connect to our sqldatasource next step is to add one button from VS Toolbox of course with one fast and simple drag & drop.

Let's change text property of our button. I will write ' Export to Excel', next step to do is one more drag & drop , now we will add most useful control that we need to make our task fast and efficient
That's AspxridiewExporter.

Only one thing we need to do with it and that is to connect AspGridViewExporter property 'GridViewID' with our AspxGridiew ID :
Next step is to make double click on our button and in his Click property write this magical command :

ASPxGridViewExporter1.WriteXlsToResponse(); // Case we use C#
Me.ASPxGridViewExporter1.WriteXlsToResponse() // or we use VB.NET
If we wish to export our AspxGridView data to some others file formats we only need to write this commands : ASPxGridViewExporter1.WriteCsvToResponse(); // for CSV file C#
ASPxGridViewExporter1.WritePdfToResponse(); // for PDF C#
ASPxGridViewExporter1.WriteRtfToResponse(); // for RTF C# Me.ASPxGridViewExporter1.WriteCsvToResponse() //for VB.NET Me.ASPxGridViewExporter1.WritePdfToResponse()
Last thing is to make run of our test site and do some simple Click on button ‘Export to Excel’ and if all goes right we will see ‘File Download ’ dialog with options Open, Save ,Cancel . We do Click on Open and we see Excel spreadsheet with our AspxGridView content in it :P

The mission ‘Fast GridView export to Excel with DevExpress controls ’ is successful.
That’s all for this post J
    Blogger Comment
    Facebook Comment


  1. Thanks a lot from Colombia. This is what I need.

  2. Your post is providing some really good information. I liked its essence and enjoyed reading it. Keep sharing such important posts about this blog and its much more helpful for us .
    Freight quote