DataGrid Export to Excel

Discussion in 'ASP .Net Datagrid Control' started by Siva Mateti, Dec 4, 2003.

  1. Siva Mateti

    Siva Mateti Guest

    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
     
    Siva Mateti, Dec 4, 2003
    #1
    1. Advertising

  2. Siva Mateti

    Siva Mateti Guest

    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

    >-----Original Message-----
    >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
    >.
    >
     
    Siva Mateti, Dec 8, 2003
    #2
    1. Advertising

  3. look at this site
    http://www.c-sharpcorner.com/Code/2003/Sept/ExportASPNetDataGridToExcel.asp

    "Siva Mateti" <> wrote in message
    news:f24201c3bd9a$f1ebedd0$...
    > 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
    >
    > >-----Original Message-----
    > >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
    > >.
    > >
     
    Alejandro Becker, Dec 23, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cowboy \(Gregory A. Beamer\)

    Export datagrid(with allowsorting) to Excel

    Cowboy \(Gregory A. Beamer\), Jun 25, 2003, in forum: ASP .Net
    Replies:
    6
    Views:
    525
  2. =?Utf-8?B?U3JpZGhhcg==?=

    using Microsoft Excel image for Export to Excel button

    =?Utf-8?B?U3JpZGhhcg==?=, Dec 9, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    3,116
    =?Utf-8?B?U3JpZGhhcg==?=
    Dec 9, 2005
  3. =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=

    Export to Excel (Default File Type - Excel)

    =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=, Apr 24, 2006, in forum: ASP .Net
    Replies:
    15
    Views:
    17,537
    syed hassan
    May 21, 2009
  4. Grey
    Replies:
    4
    Views:
    1,999
    Mark Rae [MVP]
    Oct 17, 2007
  5. Paul D. Fox

    Display a Datagrid & Export a Datagrid to Excel

    Paul D. Fox, Jul 21, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    227
    Elton Wang
    Jul 21, 2005
Loading...

Share This Page