Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Exporting data from a paged datagrid to excel

Exporting data from a paged datagrid to excel

Scheduled Pinned Locked Moved ASP.NET
helphtmldesignsysadminquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    smita_roy
    wrote on last edited by
    #1

    Hi I am using the following piece of code to export my data to an excel file Response.ContentType = "application/vnd.ms-excel" ' Remove the charset from the Content-Type header. Response.Charset = "" ' Turn off the view state. Me.EnableViewState = False Dim tw As New System.IO.StringWriter() Dim hw As New System.Web.UI.HtmlTextWriter(tw) ' Get the HTML for the control. DataGrid1.RenderControl(hw) ' Write the HTML back to the browser. Response.Write(tw.ToString()) ' End the response. Response.End() This works fine if there is only one page of data but when it has multiple pages it gives me the following error Control 'DataGrid1__ctl24__ctl1' of type 'DataGridLinkButton' must be placed inside a form tag with runat=server. How do i resolve this issue

    E M 2 Replies Last reply
    0
    • S smita_roy

      Hi I am using the following piece of code to export my data to an excel file Response.ContentType = "application/vnd.ms-excel" ' Remove the charset from the Content-Type header. Response.Charset = "" ' Turn off the view state. Me.EnableViewState = False Dim tw As New System.IO.StringWriter() Dim hw As New System.Web.UI.HtmlTextWriter(tw) ' Get the HTML for the control. DataGrid1.RenderControl(hw) ' Write the HTML back to the browser. Response.Write(tw.ToString()) ' End the response. Response.End() This works fine if there is only one page of data but when it has multiple pages it gives me the following error Control 'DataGrid1__ctl24__ctl1' of type 'DataGridLinkButton' must be placed inside a form tag with runat=server. How do i resolve this issue

      E Offline
      E Offline
      enjoycrack
      wrote on last edited by
      #2

      Hi there,

      smita_roy wrote:

      Control 'DataGrid1__ctl24__ctl1' of type 'DataGridLinkButton'

      I did not see the GridLinkControl, or maybe u rendered it in HtmlTextWriter, right?

      smita_roy wrote:

      Control 'DataGrid1__ctl24__ctl1' of type 'DataGridLinkButton' must be placed inside a form tag with runat=server.

      it sounds that the GridLinkControl is outside the

      tag Not sure... ;P << >>

      1 Reply Last reply
      0
      • S smita_roy

        Hi I am using the following piece of code to export my data to an excel file Response.ContentType = "application/vnd.ms-excel" ' Remove the charset from the Content-Type header. Response.Charset = "" ' Turn off the view state. Me.EnableViewState = False Dim tw As New System.IO.StringWriter() Dim hw As New System.Web.UI.HtmlTextWriter(tw) ' Get the HTML for the control. DataGrid1.RenderControl(hw) ' Write the HTML back to the browser. Response.Write(tw.ToString()) ' End the response. Response.End() This works fine if there is only one page of data but when it has multiple pages it gives me the following error Control 'DataGrid1__ctl24__ctl1' of type 'DataGridLinkButton' must be placed inside a form tag with runat=server. How do i resolve this issue

        M Offline
        M Offline
        minhpc_bk
        wrote on last edited by
        #3

        Hi there, When you export the datagrid control to excel, you basically render the control and send the output html markup to the the client side. When the datagrid control is rendered, it also renders its child controls, and there are a couple of controls like LinkButton .... that require to be placed in a server form when they render. So in this case, you need to clear those controls before exporting, you can have a look at an example from here[^]. Another way is to use a second datagrid that simply contains the controls for display like label ... only to do the exporting.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups