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 gridview data into excel, i got this error. Help~

exporting gridview data into excel, i got this error. Help~

Scheduled Pinned Locked Moved ASP.NET
designhelpquestionsysadminworkspace
3 Posts 2 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.
  • D Offline
    D Offline
    Dong Kim
    wrote on last edited by
    #1

    I tried to export gridview info to excel. I got this error. Control 'grdLIST' of type 'GridView' must be placed inside a form tag with runat=server. This my gridview design. <asp:GridView ID="grdLIST" runat="server" Visible="False"> </asp:GridView> I didn't setup fields, because field name is changing due to date term. This is aspx codeing protected void cmdEXCEL_Click(object sender, EventArgs e) { Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("content-disposition", "attachment;filename=CadilacReport.xls"); Response.Charset = string.Empty; Response.Cache.SetCacheability(System.Web.HttpCacheability.Public); Response.ContentType = "application/vnd.xls"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); if (grdLIST.HeaderRow != null && grdLIST.HeaderRow.Cells != null) { for (int ct = 0; ct < grdLIST.HeaderRow.Cells.Count; ct++) { string headerText = grdLIST.HeaderRow.Cells[ct].Text; if (grdLIST.HeaderRow.Cells[ct].HasControls()) { if (grdLIST.HeaderRow.Cells[ct].Controls[0].GetType().ToString() == "System.Web.UI.WebControls.DataCountrlLinkButton") { headerText = ((LinkButton)grdLIST.HeaderRow.Cells[ct].Controls[0]).Text; } grdLIST.HeaderRow.Cells[ct].Controls.Clear(); } grdLIST.HeaderRow.Cells[ct].Text = headerText; } } if (grdLIST.FooterRow != null) { grdLIST.FooterRow.Visible = false; } grdLIST.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); } at grdLIST.RenderControl(htmlWrite);, I got that error. How can I solve it? Please help.

    E 1 Reply Last reply
    0
    • D Dong Kim

      I tried to export gridview info to excel. I got this error. Control 'grdLIST' of type 'GridView' must be placed inside a form tag with runat=server. This my gridview design. <asp:GridView ID="grdLIST" runat="server" Visible="False"> </asp:GridView> I didn't setup fields, because field name is changing due to date term. This is aspx codeing protected void cmdEXCEL_Click(object sender, EventArgs e) { Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("content-disposition", "attachment;filename=CadilacReport.xls"); Response.Charset = string.Empty; Response.Cache.SetCacheability(System.Web.HttpCacheability.Public); Response.ContentType = "application/vnd.xls"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); if (grdLIST.HeaderRow != null && grdLIST.HeaderRow.Cells != null) { for (int ct = 0; ct < grdLIST.HeaderRow.Cells.Count; ct++) { string headerText = grdLIST.HeaderRow.Cells[ct].Text; if (grdLIST.HeaderRow.Cells[ct].HasControls()) { if (grdLIST.HeaderRow.Cells[ct].Controls[0].GetType().ToString() == "System.Web.UI.WebControls.DataCountrlLinkButton") { headerText = ((LinkButton)grdLIST.HeaderRow.Cells[ct].Controls[0]).Text; } grdLIST.HeaderRow.Cells[ct].Controls.Clear(); } grdLIST.HeaderRow.Cells[ct].Text = headerText; } } if (grdLIST.FooterRow != null) { grdLIST.FooterRow.Visible = false; } grdLIST.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); } at grdLIST.RenderControl(htmlWrite);, I got that error. How can I solve it? Please help.

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

      Hi, If you look at your source code of your aspx page, you might be missing the following tag below the body tag.

      (Your grid declaration should be in here)

      Hope this solves your problem. Regards, Elizma

      D 1 Reply Last reply
      0
      • E Elizma

        Hi, If you look at your source code of your aspx page, you might be missing the following tag below the body tag.

        (Your grid declaration should be in here)

        Hope this solves your problem. Regards, Elizma

        D Offline
        D Offline
        Dong Kim
        wrote on last edited by
        #3

        I do have that tag in aspx page coding. Anything else?

        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