473,396 Members | 2,090 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,396 software developers and data experts.

Exporting datagrid to Excel

I got some code off of dotnetjunkies.com to export a datagrid to excel.
Everything works fine when I test it on my localhost, but when I move
it to a server it doesn't do anything (no errors, just a plain
postback).

What am I missing?
Is it a security issue?

Any help appreciated and here the code:

HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ContentType =
"application/vnd.ms-excel"

HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename=" & saveAsFile & ".xls")
' Remove the charset from the Content-Type header.
HttpContext.Current.Response.Charset = ""
'HttpContext.Current.Response.WriteFile("style.txt ")
' Turn off the view state.
grid.EnableViewState = False
Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)

grid.RenderControl(hw)
' Write the HTML back to the browser.
HttpContext.Current.Response.Write(tw.ToString())
' End the response.
HttpContext.Current.Response.End()

Nov 30 '05 #1
1 1228
Also do a clearheaders() and ClearContents() if you have authentication.
Debug/step?
"Alex A." <mb********@gmail.com> schreef in bericht
news:11*********************@f14g2000cwb.googlegro ups.com...
I got some code off of dotnetjunkies.com to export a datagrid to excel.
Everything works fine when I test it on my localhost, but when I move
it to a server it doesn't do anything (no errors, just a plain
postback).

What am I missing?
Is it a security issue?

Any help appreciated and here the code:

HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ContentType =
"application/vnd.ms-excel"

HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename=" & saveAsFile & ".xls")
' Remove the charset from the Content-Type header.
HttpContext.Current.Response.Charset = ""
'HttpContext.Current.Response.WriteFile("style.txt ")
' Turn off the view state.
grid.EnableViewState = False
Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)

grid.RenderControl(hw)
' Write the HTML back to the browser.
HttpContext.Current.Response.Write(tw.ToString())
' End the response.
HttpContext.Current.Response.End()

Nov 30 '05 #2

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

Similar topics

5
by: Neil | last post by:
Hi I'm currently exporting my datagrid to excel, taking advantage of the fact that excel can render html, the problem is that when i click the button to export it opens in browser, I want the button...
1
by: ad | last post by:
I use the code below to export the content of a data set to Excel, the code come form http://www.dotnetjohn.com/articles.aspx?articleid=36 But it always use the web form's name as the default...
4
by: Hitesh | last post by:
Hi, I have three datagrid control on my aspx page and one export to excel button, i want to export all the 3 datagrids contents in one excel file. how can i achive that? -- Thanks Hitesh
2
by: bienwell | last post by:
Hi, I have a question about exporting data from datagrid control into Excel file in ASP.NET. On my Web page, I have a linkbutton "Export data". This link will call a Sub Function to perform...
6
by: Opa | last post by:
Hi, I have a DataGrid, whose sourceI am exporting to Excel. This works fine except for the Column ordering. My datasource is not a datatable, with a typical SELECT statement where I can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
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
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.