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 Asp.net controls toolkit (8.2.4). That's mean DevExpress toolkit is requirement.
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.
After we successfully connect to our sqldatasource next step is to add one button from VS Toolbox of course with one fast andsimple 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#
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 AspxGridViewcontent in it :P
No comments:
Post a Comment