Exporting datagrid to Excel

A

Alex A.

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()
 
E

Edwin Knoppert

Also do a clearheaders() and ClearContents() if you have authentication.
Debug/step?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top