471,350 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Export Datagrid to Excel Save As

I was looking for the easiest way to take a datagrid full of data including
two template columns, and export the contents of the grid into Excel by
giving an "open or save as" box.

I came across the following control which I thought might do it:


However, I'm not sure if I added the control correctly to my project via
VS2003 or if I am handling the Datagrid to what appears to be required as a
DataView for the Control.

Webform works fine without the control button added.

The error I'm currently getting is:

Unable to generate code for a value of type 'System.Data.DataView'. This
error occurred while trying to generate the property value for Dataview.
Code is as follows:

<pnwc:exportbutton id="ExportButton1" runat="server"
FileNameToExport="rptAttachmentFiles.xls" ExportType="Excel"
Protected WithEvents ExportButton1 As PNayak.Web.UI.WebControls.ExportButton

My first thought was to try:

Dim DataTable1 As DataTable
Dim DataView1 As DataView
DataTable1 = CType(DataGrid1.DataSource, DataTable)
DataView1 = DataTable1.DefaultView

to convert the Datagrid to a DataView. Is that correct?

Also, doesn't matter if I rem out these DataTable and DataView lines. Same

Thank you in advance.

Jul 21 '05 #1
1 4297
Hi Rob,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that when you're using a 3rd-party control
to generate an Excel file from the DataGrid. If there is any
misunderstanding, please feel free to let me know.

When we're getting the DataSource from the DataGrid, we have to cast it to
the original type when we assign it to the DataGrid.DataSource property. So
if you use a DataTable as the datasource, please cast it to DataTable type.
Since it's a third party control with source code, you can try to trace
into the source code to see what is going wrong.

Actually, it will also be simple for us to export the grid data to an Excel
table with our own code. We can go through each row, write everything we
need to a CSV format text file and save it as an .xls file.


Kevin Yu
"This posting is provided "AS IS" with no warranties, and confers no

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Kevin Blakeley | last post: by
11 posts views Thread by Grey | last post: by
2 posts views Thread by C | last post: by
1 post views Thread by Rob | last post: by
2 posts views Thread by Arvind R | last post: by
13 posts views Thread by Hemant Sipahimalani | last post: by
1 post views Thread by anjupt | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.