473,394 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Export Datagrid to Excel Save As

Rob
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:

http://www.codeproject.com/aspnet/Ex...ort_button.asp

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"
DataView="DataView1"></pnwc:exportbutton>
....
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
error.

Thank you in advance.

Rob
Jul 21 '05 #1
1 4483
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.

HTH.

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

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kevin Blakeley | last post by:
I know this was just posted but I did not want this message to get lost in the other thread as it's slightly different. Yes I want to export my dataset to excel for my clients, but I don't want...
11
by: Grey | last post by:
is it possible to export excel directly from ASP.NET to Excel? My requirement is that the data on the datagrid is exported to MS Excel file after user clicks the button on the web page. Excel will be...
2
by: C | last post by:
Hi, I have a dataset which I bind to a datagrid on my ASPX. I then export the datagrid to Excel and stream the file to the user by setting the MIME Type etc etc. Response.ContentType =...
1
by: Rob | last post by:
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...
2
by: Arvind R | last post by:
Hello, how to ask saveas dialog before writing the data to the excel file? right now im able to save in c drive or any other specified location only. any solution will be a great help! ...
7
by: mattmerc | last post by:
Hi all, We have all seen lot of method for exporting datagrids to Excel. I have a slightly different need. I think it should be easy to accomplish but I am not sure how. I would like when a user...
3
by: ABC | last post by:
What methods can export excel file from stored procedure with parameters which input from web form?
13
by: Hemant Sipahimalani | last post by:
The following piece of code is being used to export HTML to excel. HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"...
1
by: anjupt | last post by:
Hi, I can export a datagrid into excel format by following code on button click "Response.ContentType = "application/vnd.ms-excel" clicking on the button open a dialog box asking whether to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.