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. Excel Conversion Error

Excel Conversion Error

Scheduled Pinned Locked Moved ASP.NET
helpdesignsysadmin
18 Posts 5 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
    DKalepu
    wrote on last edited by
    #1

    Hi All, I need some help. I'm trying to export Gridview into Excel. But i'm getting the following error! "Control 'myGridView' of type 'GridView' must be placed inside a form tag with runat=server." Here is my Code: protected void BtnExport_Click(object sender, EventArgs e) { Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=FileName.xls"); Response.Charset = ""; // If you want the option to open the Excel file without saving then // comment out the line below // Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/ms-excel.xls"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); myGridView.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); } THIS IS THE GRIDVIEW THAT I'M USING:: But my Gridview is already placed in the form only!!!!:((:confused: could any one please help me on

    _ S D J V 6 Replies Last reply
    0
    • D DKalepu

      Hi All, I need some help. I'm trying to export Gridview into Excel. But i'm getting the following error! "Control 'myGridView' of type 'GridView' must be placed inside a form tag with runat=server." Here is my Code: protected void BtnExport_Click(object sender, EventArgs e) { Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=FileName.xls"); Response.Charset = ""; // If you want the option to open the Excel file without saving then // comment out the line below // Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/ms-excel.xls"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); myGridView.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); } THIS IS THE GRIDVIEW THAT I'M USING:: But my Gridview is already placed in the form only!!!!:((:confused: could any one please help me on

      _ Offline
      _ Offline
      _AK_
      wrote on last edited by
      #2

      Your gridview is a server control and that control have to inside the form with runat=server tag. Add runat=server to your form tag.

      Apurva Kaushal

      1 Reply Last reply
      0
      • D DKalepu

        Hi All, I need some help. I'm trying to export Gridview into Excel. But i'm getting the following error! "Control 'myGridView' of type 'GridView' must be placed inside a form tag with runat=server." Here is my Code: protected void BtnExport_Click(object sender, EventArgs e) { Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=FileName.xls"); Response.Charset = ""; // If you want the option to open the Excel file without saving then // comment out the line below // Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/ms-excel.xls"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); myGridView.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); } THIS IS THE GRIDVIEW THAT I'M USING:: But my Gridview is already placed in the form only!!!!:((:confused: could any one please help me on

        S Offline
        S Offline
        Sathesh Sakthivel
        wrote on last edited by
        #3

        Please add the Runat= server tag in your Grid view and run ur application.

        Regards, Satips.:rose:

        _ 1 Reply Last reply
        0
        • S Sathesh Sakthivel

          Please add the Runat= server tag in your Grid view and run ur application.

          Regards, Satips.:rose:

          _ Offline
          _ Offline
          _AK_
          wrote on last edited by
          #4

          I think runat=server has to be added in form control not in gridview.

          Apurva Kaushal

          S 1 Reply Last reply
          0
          • _ _AK_

            I think runat=server has to be added in form control not in gridview.

            Apurva Kaushal

            S Offline
            S Offline
            Sathesh Sakthivel
            wrote on last edited by
            #5

            Yes. Runat=server has to be added in the form Control.

            Regards, Satips.:rose:

            1 Reply Last reply
            0
            • D DKalepu

              Hi All, I need some help. I'm trying to export Gridview into Excel. But i'm getting the following error! "Control 'myGridView' of type 'GridView' must be placed inside a form tag with runat=server." Here is my Code: protected void BtnExport_Click(object sender, EventArgs e) { Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=FileName.xls"); Response.Charset = ""; // If you want the option to open the Excel file without saving then // comment out the line below // Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/ms-excel.xls"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); myGridView.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); } THIS IS THE GRIDVIEW THAT I'M USING:: But my Gridview is already placed in the form only!!!!:((:confused: could any one please help me on

              D Offline
              D Offline
              DKalepu
              wrote on last edited by
              #6

              Thank you all for the quick response!!! my Form tag & Gridview both contains "runat=server" tag in it! ~!!! but no use! grrrrrrr!

              _ 1 Reply Last reply
              0
              • D DKalepu

                Thank you all for the quick response!!! my Form tag & Gridview both contains "runat=server" tag in it! ~!!! but no use! grrrrrrr!

                _ Offline
                _ Offline
                _AK_
                wrote on last edited by
                #7

                I think there would be some mismatch can you show us the form tag code?

                Apurva Kaushal

                D 1 Reply Last reply
                0
                • _ _AK_

                  I think there would be some mismatch can you show us the form tag code?

                  Apurva Kaushal

                  D Offline
                  D Offline
                  DKalepu
                  wrote on last edited by
                  #8

                  yes, here is my form tag code:

                  Company

                  Address

                  Telephone

                  Fax

                  Email

                  _ 1 Reply Last reply
                  0
                  • D DKalepu

                    yes, here is my form tag code:

                    Company

                    Address

                    Telephone

                    Fax

                    Email

                    _ Offline
                    _ Offline
                    _AK_
                    wrote on last edited by
                    #9

                    This peace of code works fine for me. I executed that one and is performing well.

                    Apurva Kaushal

                    D 1 Reply Last reply
                    0
                    • _ _AK_

                      This peace of code works fine for me. I executed that one and is performing well.

                      Apurva Kaushal

                      D Offline
                      D Offline
                      DKalepu
                      wrote on last edited by
                      #10

                      hmm...but whats wrong from my side: I executed it again but still the same error persists here is the error:: Control 'myGridView' of type 'GridView' must be placed inside a form tag with runat=server. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Web.HttpException: Control 'myGridView' of type 'GridView' must be placed inside a form tag with runat=server. Source Error: Line 63: System.IO.StringWriter stringWrite = new System.IO.StringWriter(); Line 64: System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); Line 65: myGridView.RenderControl(htmlWrite); Line 66: Response.Write(stringWrite.ToString()); Line 67: Response.End();

                      D 1 Reply Last reply
                      0
                      • D DKalepu

                        hmm...but whats wrong from my side: I executed it again but still the same error persists here is the error:: Control 'myGridView' of type 'GridView' must be placed inside a form tag with runat=server. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Web.HttpException: Control 'myGridView' of type 'GridView' must be placed inside a form tag with runat=server. Source Error: Line 63: System.IO.StringWriter stringWrite = new System.IO.StringWriter(); Line 64: System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); Line 65: myGridView.RenderControl(htmlWrite); Line 66: Response.Write(stringWrite.ToString()); Line 67: Response.End();

                        D Offline
                        D Offline
                        DKalepu
                        wrote on last edited by
                        #11

                        its showing the error at Line 65.

                        1 Reply Last reply
                        0
                        • D DKalepu

                          Hi All, I need some help. I'm trying to export Gridview into Excel. But i'm getting the following error! "Control 'myGridView' of type 'GridView' must be placed inside a form tag with runat=server." Here is my Code: protected void BtnExport_Click(object sender, EventArgs e) { Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=FileName.xls"); Response.Charset = ""; // If you want the option to open the Excel file without saving then // comment out the line below // Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/ms-excel.xls"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); myGridView.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); } THIS IS THE GRIDVIEW THAT I'M USING:: But my Gridview is already placed in the form only!!!!:((:confused: could any one please help me on

                          J Offline
                          J Offline
                          Jay_se
                          wrote on last edited by
                          #12

                          In order to overcome the error, We have to override the below function. public override void VerifyRenderingInServerForm(Control control) { }

                          Regards, Jay :)

                          V 1 Reply Last reply
                          0
                          • D DKalepu

                            Hi All, I need some help. I'm trying to export Gridview into Excel. But i'm getting the following error! "Control 'myGridView' of type 'GridView' must be placed inside a form tag with runat=server." Here is my Code: protected void BtnExport_Click(object sender, EventArgs e) { Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=FileName.xls"); Response.Charset = ""; // If you want the option to open the Excel file without saving then // comment out the line below // Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/ms-excel.xls"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); myGridView.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); } THIS IS THE GRIDVIEW THAT I'M USING:: But my Gridview is already placed in the form only!!!!:((:confused: could any one please help me on

                            V Offline
                            V Offline
                            Venkatesh Mookkan
                            wrote on last edited by
                            #13

                            DKalepu wrote:

                            myGridView.RenderControl(htmlWrite);

                            You cannot render the GridView Control into HTML directly. Use DataGrid. May be Jay_se is correct. But I haven't tried that before. We also had this issue before and we solve that using DataGrid. We can used JavaScript get the HTML String of the GridView and do the same.

                            Regards, Venkatesh Mookkan. Software Engineer, India My: Website | Yahoo Group | Blog Spot

                            J 1 Reply Last reply
                            0
                            • V Venkatesh Mookkan

                              DKalepu wrote:

                              myGridView.RenderControl(htmlWrite);

                              You cannot render the GridView Control into HTML directly. Use DataGrid. May be Jay_se is correct. But I haven't tried that before. We also had this issue before and we solve that using DataGrid. We can used JavaScript get the HTML String of the GridView and do the same.

                              Regards, Venkatesh Mookkan. Software Engineer, India My: Website | Yahoo Group | Blog Spot

                              J Offline
                              J Offline
                              Jay_se
                              wrote on last edited by
                              #14

                              Hi,

                              Venkatesh MookkanYou cannot render the GridView Control into HTML directly.

                              We Can do Vankat. It works fine too.

                              Regards, Jay :)

                              V 1 Reply Last reply
                              0
                              • J Jay_se

                                Hi,

                                Venkatesh MookkanYou cannot render the GridView Control into HTML directly.

                                We Can do Vankat. It works fine too.

                                Regards, Jay :)

                                V Offline
                                V Offline
                                Venkatesh Mookkan
                                wrote on last edited by
                                #15

                                If it works fine, then no problem for me man.. Thanks...

                                Regards, Venkatesh Mookkan. Software Engineer, India My: Website | Yahoo Group | Blog Spot

                                1 Reply Last reply
                                0
                                • D DKalepu

                                  Hi All, I need some help. I'm trying to export Gridview into Excel. But i'm getting the following error! "Control 'myGridView' of type 'GridView' must be placed inside a form tag with runat=server." Here is my Code: protected void BtnExport_Click(object sender, EventArgs e) { Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=FileName.xls"); Response.Charset = ""; // If you want the option to open the Excel file without saving then // comment out the line below // Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/ms-excel.xls"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); myGridView.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); } THIS IS THE GRIDVIEW THAT I'M USING:: But my Gridview is already placed in the form only!!!!:((:confused: could any one please help me on

                                  D Offline
                                  D Offline
                                  DKalepu
                                  wrote on last edited by
                                  #16

                                  Hi, Thank you very much for the help Jay.. That piece of code solved my problem..... Thank you so much once again to all of you for helping on my problem/ :-D

                                  1 Reply Last reply
                                  0
                                  • J Jay_se

                                    In order to overcome the error, We have to override the below function. public override void VerifyRenderingInServerForm(Control control) { }

                                    Regards, Jay :)

                                    V Offline
                                    V Offline
                                    Venkatesh Mookkan
                                    wrote on last edited by
                                    #17

                                    Cool stuff man... I will rate this... :)

                                    Regards, Venkatesh Mookkan. Software Engineer, India My: Website | Yahoo Group | Blog Spot

                                    J 1 Reply Last reply
                                    0
                                    • V Venkatesh Mookkan

                                      Cool stuff man... I will rate this... :)

                                      Regards, Venkatesh Mookkan. Software Engineer, India My: Website | Yahoo Group | Blog Spot

                                      J Offline
                                      J Offline
                                      Jay_se
                                      wrote on last edited by
                                      #18

                                      Thanks:-O (For Nellai Website Too) -- modified at 5:45 Wednesday 13th June, 2007

                                      Regards, Jay :)

                                      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