DataGrid Export to Excel

S

Siva Mateti

I'm having some problems with exporting datagrid to
excel. First I had problems with Datagridlink buttons
(for paging and sorting), which I solved by iterating
through the datagrid and replacing all the link buttons
with literal control. Then I thought this following code
snippet would work:

Response.Clear()
Response.Buffer = True
Response.ContentType = "application/vnd.ms- excel"
Response.Charset = ""
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
DataGrid2.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()

But after I run the snippet either nothing happens
or "page cannot be displayed" error occurs. I looked into
the process explorer and EXCEL.EXE seems to be running.
Also I turned the trace on to look at the content type and
I got "application/x-www-form-urlencoded".

Can anyone please explain me how to do it?

Thanks
Siva Mateti
 
S

Siva Mateti

I still could not solve my problem, but I got more
feedback. One reason I think why my code is not working
because I'm using an user control which after doing all
excel export, posts data back to the regular aspx page.
Now the aspx page is still set to receive text/html rather
than "application/vnd.ms- excel". I think it is here some
kind of conflict occuring. I couldn't figure out how to
avoid this. Hopefully someone can answer for me!

BTW, I figured out "application/x-www-form-urlencoded".

Thanks
Siva Mateti
 

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

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top