First, get the control and add it to your Visual Studio 2005 toolbox.
Now, what if you have a gridview on your page that's filtered? Say your database table has 30 fields but your Gridview only shows 3 of them so that you can link to a detail view, but you want to export the entire database table to Excel. If you only have one Gridview on your aspx page and it displays all of the fields you want, then this is fine b/c the control does this by default. Here's a quick tip to export then entire table if this is not the case:
- Inserted a new Gridview called GridViewHiddenExcel which had autogenerated fields (so all columns would be included - you could even use the same datasource as your original filtered Gridview)
- Set the GridViewHiddenExcel's Visible property to False
- Enable Paging and set the Pagersize to 1 (so that it only loads 1 record, the control's default behavior is to export all of the records even with paging enabled)
- Drag the Export to Excel control onto your page and set its GridViewID property to GridViewHiddenExcel - you only have to do this if your initial Gridview didn't have all of the fields your needed for your exported spreadsheet
There you go - almost instant Excel export!
Bonus Un-Related Tip: Adding a Confirmation to your Delete Button
Simply add the default Delete button to the Gridview (or DetailsView or whatever) and then click:

Add this to the new button code:
OnClientClick="return confirm('Are you sure you want to delete this record?');"
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5