Export GridView to Excel Error

Discussion in 'ASP .Net' started by =?Utf-8?B?bWFuaWthMDI=?=, Feb 21, 2007.

  1. Hi,
    I have a GridView control in page called eventslisting which is inheriting
    from a MasterPage. The normal code to export to GridView does not work and
    gives me an error - "Control of type GridView must be placed inside form tag
    with runat = server". I understand that this is because my Masterpage has the
    formtag and not the eventslisting page.
    As a workaround I programatically created an HTML form, added runat=server
    attribute to it and then added the gridview to it programatically as

    frm.Controls.Add(dgTemp);

    But I get the same error - "Control of type GridView must be placed inside
    form tag with runat = server". when I perform the step

    dgTemp.RenderControl(htmlWrite);

    Please advise of any solution to this problem that might work.

    Thanks,
     
    =?Utf-8?B?bWFuaWthMDI=?=, Feb 21, 2007
    #1
    1. Advertising

  2. manika02,

    I could able to create a child page (inherited from a Master) with a
    GridViewControl and making the Export to excel work.

    I've defined my gridview like the following in the designer
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
    Runat="Server">
    <asp:GridView ID="GridView1" runat="server">
    </asp:GridView>

    I programatically bounded this control from SQL DataSource. Now i'm able
    to export to excel. Please explain me in detail what's your problem

    </asp:Content>
    --
    Thanks & Regards,
    Mark Nelson


    "manika02" wrote:

    >
    > Hi,
    > I have a GridView control in page called eventslisting which is inheriting
    > from a MasterPage. The normal code to export to GridView does not work and
    > gives me an error - "Control of type GridView must be placed inside form tag
    > with runat = server". I understand that this is because my Masterpage has the
    > formtag and not the eventslisting page.
    > As a workaround I programatically created an HTML form, added runat=server
    > attribute to it and then added the gridview to it programatically as
    >
    > frm.Controls.Add(dgTemp);
    >
    > But I get the same error - "Control of type GridView must be placed inside
    > form tag with runat = server". when I perform the step
    >
    > dgTemp.RenderControl(htmlWrite);
    >
    > Please advise of any solution to this problem that might work.
    >
    > Thanks,
    >
    >
    >
     
    =?Utf-8?B?TWFyayBOZWxzb24=?=, Feb 22, 2007
    #2
    1. Advertising

  3. =?Utf-8?B?bWFuaWthMDI=?=

    Larry Bud Guest

    On Feb 22, 6:53 am, Mark Nelson <>
    wrote:
    > > I have aGridViewcontrolin page called eventslisting which is inheriting
    > > from a MasterPage. The normal code to export toGridViewdoes not work and
    > > gives me an error - "ControloftypeGridViewmustbeplacedinsideformtag
    > > withrunat = server". I understand that this is because my Masterpage has the
    > > formtag and not the eventslisting page.
    > > As a workaround I programatically created an HTMLform, addedrunat=server
    > > attribute to it and then added thegridviewto it programatically as

    >
    > > frm.Controls.Add(dgTemp);

    >
    > > But I get the same error - "ControloftypeGridViewmustbeplacedinside
    > >formtagwithrunat = server". when I perform the step

    >
    > > dgTemp.RenderControl(htmlWrite);

    >
    > > Please advise of any solution to this problem that might work.

    >
    > manika02,
    >
    > I could able to create a child page (inherited from a Master) with a
    > GridViewControl and making the Export to excel work.
    >
    > I've defined mygridviewlike the following in the designer
    > <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server">
    > <asp:GridViewID="GridView1"runat="server">
    > </asp:GridView>
    >
    > I programatically bounded thiscontrolfrom SQL DataSource. Now i'm able
    > to export to excel. Please explain me in detail what's your problem
    >
    > </asp:Content>


    Mark, I have the same problem. What's your code to export to Excel?

    The only success I've had is creating a separate page with the
    GridView, and adding the changing the ContentType To Excel in the
    Page_Load event. However, ASP.NET loves to generate some extra stuff
    that messes with the format in Excel, and I end up getting a blank row
    at the top of the excel file.
     
    Larry Bud, Feb 26, 2007
    #3
  4. =?Utf-8?B?bWFuaWthMDI=?=

    Larry Bud Guest

    On Feb 26, 9:05 am, "Larry Bud" <> wrote:
    > On Feb 22, 6:53 am, Mark Nelson <>
    > wrote:
    >
    >
    >
    >
    >
    > > > I have aGridViewcontrolin page called eventslisting which is inheriting
    > > > from a MasterPage. The normal code to export toGridViewdoes not work and
    > > > gives me an error - "ControloftypeGridViewmustbeplacedinsideformtag
    > > > withrunat = server". I understand that this is because my Masterpage has the
    > > > formtag and not the eventslisting page.
    > > > As a workaround I programatically created an HTMLform, addedrunat=server
    > > > attribute to it and then added thegridviewto it programatically as

    >
    > > > frm.Controls.Add(dgTemp);

    >
    > > > But I get the same error - "ControloftypeGridViewmustbeplacedinside
    > > >formtagwithrunat = server". when I perform the step

    >
    > > > dgTemp.RenderControl(htmlWrite);

    >
    > > > Please advise of any solution to this problem that might work.

    >
    > > manika02,

    >
    > > I could able to create a child page (inherited from a Master) with a
    > > GridViewControl and making the Export to excel work.

    >
    > > I've defined mygridviewlike the following in the designer
    > > <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server">
    > > <asp:GridViewID="GridView1"runat="server">
    > > </asp:GridView>

    >
    > > I programatically bounded thiscontrolfrom SQL DataSource. Now i'm able
    > > to export to excel. Please explain me in detail what's your problem

    >
    > > </asp:Content>

    >
    > Mark, I have the same problem. What's your code to export to Excel?
    >
    > The only success I've had is creating a separate page with the
    > GridView, and adding the changing the ContentType To Excel in the
    > Page_Load event. However, ASP.NET loves to generate some extra stuff
    > that messes with the format in Excel, and I end up getting a blank row
    > at the top of the excel file.- Hide quoted text -
    >
    > - Show quoted text -


    Unreal, I worked on this for the last 2 days, and I find the solution
    in about 30 minutes this morning. You need to override the function
    which verifies that your GridView is within a form:

    Public Overrides Sub VerifyRenderingInServerForm(ByVal control As
    Control)

    End Sub
     
    Larry Bud, Feb 26, 2007
    #4
    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. =?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,160
    =?Utf-8?B?U3JpZGhhcg==?=
    Dec 9, 2005
  2. =?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,658
    syed hassan
    May 21, 2009
  3. Grey
    Replies:
    4
    Views:
    2,112
    Mark Rae [MVP]
    Oct 17, 2007
  4. JohnE
    Replies:
    6
    Views:
    5,274
    praveenbattula
    Oct 9, 2010
  5. JumpingMattFlash

    Using Gridview To Export Data To Excel Error (ASP.NET 2.0)

    JumpingMattFlash, Aug 25, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    293
    JumpingMattFlash
    Aug 25, 2006
Loading...

Share This Page