Exporting datagrid to Excel

Discussion in 'ASP .Net' started by Alex A., Nov 30, 2005.

  1. Alex A.

    Alex A. Guest

    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

    What am I missing?
    Is it a security issue?

    Any help appreciated and here the code:

    HttpContext.Current.Response.ContentType =

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

    ' Write the HTML back to the browser.
    ' End the response.
    Alex A., Nov 30, 2005
    1. Advertisements

  2. Also do a clearheaders() and ClearContents() if you have authentication.
    Edwin Knoppert, Nov 30, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.