473,395 Members | 1,530 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,395 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 4485
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.