472,331 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Export Datagrid to Excel

Hi,

I have to export data inside the datagrid into an excel worksheet. I have
to do this on button click event. I am trying to do like this.

First get the DataTable from the datagrid and iterate through each row to
get the data. I am not able to get the DataTable from the datagrid. How could
I do that? I tried like this but it is not working

Dim dt as DataTable = CType(datagrid1.DataSource, DataTable)

I have also tried this

Dim t as Table = datagrid1.Controls(0). This one is giving the data in the
form of a table. but the problem is, If I have a datagrid that contains
LinkButtons and If I need to get the text of that LinkButtons, it is not
getting them. Is there a way to get the full data even the text on the
controls so that I could export it to excel?

Thnx!
Jan 3 '06 #1
6 3592
Hi Sridhar,

A while ago i came across this site
http://www.c-sharpcorner.com/Code/20...ridToExcel.asp .
This might help.
Good luck.
"Sridhar" wrote:
Hi,

I have to export data inside the datagrid into an excel worksheet. I have
to do this on button click event. I am trying to do like this.

First get the DataTable from the datagrid and iterate through each row to
get the data. I am not able to get the DataTable from the datagrid. How could
I do that? I tried like this but it is not working

Dim dt as DataTable = CType(datagrid1.DataSource, DataTable)

I have also tried this

Dim t as Table = datagrid1.Controls(0). This one is giving the data in the
form of a table. but the problem is, If I have a datagrid that contains
LinkButtons and If I need to get the text of that LinkButtons, it is not
getting them. Is there a way to get the full data even the text on the
controls so that I could export it to excel?

Thnx!

Jan 3 '06 #2
May I also recommend the following for VB programmers, I use this one
to export my grid to Excel. Works like a charm.

http://dotnetjunkies.com/WebLog/stef.../01/27337.aspx

Jan 4 '06 #3
Hi Alex,

Thanks for the reply. It is working fine for some pages. But for some
pages it is exporting the whole page not just the datagrid. I am thinking it
is due to the HttpContext.Current property. Is there a way to clear all the
data and just export the datagrid?

Thanks,
Sridhar.

"Alex A." wrote:
May I also recommend the following for VB programmers, I use this one
to export my grid to Excel. Works like a charm.

http://dotnetjunkies.com/WebLog/stef.../01/27337.aspx

Jan 4 '06 #4
I see a lot of the same code out there to export data from an ASP.NET
DataGrid to Excel. All the solutions are pretty similar. One thing I have
noticed with the solution(s) provided is that if a user opens the file,
rather than saving it, the Excel file will open in the user's browser window
and disable the Back button. How can you allow a user to open the Excel file
(instead of saving it off first) and be able to use the Back button to get
back to the site?

Thanks!

Brian

"Sridhar" wrote:
Hi Alex,

Thanks for the reply. It is working fine for some pages. But for some
pages it is exporting the whole page not just the datagrid. I am thinking it
is due to the HttpContext.Current property. Is there a way to clear all the
data and just export the datagrid?

Thanks,
Sridhar.

"Alex A." wrote:
May I also recommend the following for VB programmers, I use this one
to export my grid to Excel. Works like a charm.

http://dotnetjunkies.com/WebLog/stef.../01/27337.aspx

Feb 24 '06 #5
I have the same problem as you, Have you found a solution?
--
Kenny M.
"Sridhar" wrote:
Hi Alex,

Thanks for the reply. It is working fine for some pages. But for some
pages it is exporting the whole page not just the datagrid. I am thinking it
is due to the HttpContext.Current property. Is there a way to clear all the
data and just export the datagrid?

Thanks,
Sridhar.

"Alex A." wrote:
May I also recommend the following for VB programmers, I use this one
to export my grid to Excel. Works like a charm.

http://dotnetjunkies.com/WebLog/stef.../01/27337.aspx

Mar 16 '06 #6
Nope...Never found a solution to it...be sure to post back here if you find
one!!

Brian

"Kenny M." wrote:
I have the same problem as you, Have you found a solution?
--
Kenny M.
"Sridhar" wrote:
Hi Alex,

Thanks for the reply. It is working fine for some pages. But for some
pages it is exporting the whole page not just the datagrid. I am thinking it
is due to the HttpContext.Current property. Is there a way to clear all the
data and just export the datagrid?

Thanks,
Sridhar.

"Alex A." wrote:
May I also recommend the following for VB programmers, I use this one
to export my grid to Excel. Works like a charm.

http://dotnetjunkies.com/WebLog/stef.../01/27337.aspx

Mar 16 '06 #7

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

Similar topics

6
by: Eric | last post by:
Dear All, I want to export datagrid content to a Excel file, the code just like below: Response.ContentType = "application/vnd.ms-excel"...
2
by: Bidarkota | last post by:
Hi, I have a DataGrid in which there are some images and Data are displayed and in the webform.asp page i am using some stylesheets. when i...
3
by: Bidarkota | last post by:
When i export DataGrid to Excel all the HTML contents are also exporting to excel. i am using stylesheets in the ASPX Page and i am getting an alert...
0
by: sunilkumar Reddy via DotNetMonster.com | last post by:
hai all first we have taken binded grid Export to excel data from ultrawebgrid (or) datagrid rows, Each row data Expoting to one worksheet in...
0
by: kieran | last post by:
Hi, I have an 'export to excel' button on my Datagrid. All works well except that on my Datagrid, I have sub total rows. The subtotal rows use...
4
by: Frank | last post by:
Hello All, I ham using VS.NET 2003. Have followed instructions from http://gridviewguy.com/ArticleDetails.aspx?articleID=26 along with several...
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...
19
by: cj2 | last post by:
#1 Is there a quick way to export a datatable to an excel file? Or delimited file? #2 Where is the appropriate Microsoft monitored group to...
5
by: Reggie | last post by:
Hi and TIA! I have an export procedure that exports my data from my datagrids to excel. The problem is that I lose leading zero's cause excel...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.