Archive for October, 2008

GridView To DataSet To Excel

Cross Posted From Here

My weekend was a bit busy as I am working on a small project and one of the requirements that I have been doing is converting GridView data to an Excel document. I checked the resources in the internet and I can’t seem to find anything that fits my need. Things become more difficult as I am working on dynamic GridViews where the number of GridViews that would be displayed on a certain instance depends on the value that will be returned by the query as well as the text in some of the cells that it should contain.

Researching further, I found an article converting DataSets to Microsoft Excel without the use of COM objects. This would be a good headstart to keep things rolling. Though, I found no explicit API that allows me to convert GridView data to DataSets. Moreover, I do customizations on display on my GridView so I prefer to have an exported data that outputs the same content in the Excel worksheet as on my screen.

GridView objects have an event called RowDataBound and this allows the developer to access the value of the fields before it is displayed in a GridView. This is quite helpful in cases wherein if you want to customize display text in a BoundField column from a bit-typed DataField source rather than from a default true/false display to something more descriptive (which in case in an ordering system, display “Delivered/Not Yet Delivered” than a “true/false” value). Having that in mind, I played with the event and created a dynamic DataTable out of the value rendered in the GridView. In my example, I used the Northwind database and queried the Customers table with a SqlDataSource. There are 2 GridViews in my form where the first one consumes the result of the SqlDataSource and the other one that will consume the generated DataSet (I have a decided to append my generated DataTable to a DataSet so that I can consume the code indicated above) from the first GridView.

Continue reading ‘GridView To DataSet To Excel’


Tags

Blog Stats

  • 2,757 hits

 

October 2008
S M T W T F S
« Aug   Nov »
 1234
567891011
12131415161718
19202122232425
262728293031  

Follow

Get every new post delivered to your Inbox.