Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Export GridView to Excel Error

Reply
Thread Tools

Export GridView to Excel Error

 
 
=?Utf-8?B?bWFuaWthMDI=?=
Guest
Posts: n/a
 
      02-21-2007

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,



 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWFyayBOZWxzb24=?=
Guest
Posts: n/a
 
      02-22-2007
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,
>
>
>

 
Reply With Quote
 
 
 
 
Larry Bud
Guest
Posts: n/a
 
      02-26-2007
On Feb 22, 6:53 am, Mark Nelson <(E-Mail Removed)>
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 - "ControloftypeGridViewmustbeplacedinsideformta g
> > 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="S erver">
> <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.

 
Reply With Quote
 
Larry Bud
Guest
Posts: n/a
 
      02-26-2007
On Feb 26, 9:05 am, "Larry Bud" <(E-Mail Removed)> wrote:
> On Feb 22, 6:53 am, Mark Nelson <(E-Mail Removed)>
> 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 - "ControloftypeGridViewmustbeplacedinsideformta g
> > > 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="S erver">
> > <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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
export gridview to excel format error JohnE ASP .Net 6 10-09-2010 09:33 AM
Export to Excel (Default File Type - Excel) =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?= ASP .Net 15 05-21-2009 12:01 PM
Export to excel in asp.net using excel template Grey ASP .Net 4 10-17-2007 08:08 AM
Using Gridview To Export Data To Excel Error (ASP.NET 2.0) JumpingMattFlash ASP .Net Web Controls 0 08-25-2006 02:41 PM
using Microsoft Excel image for Export to Excel button =?Utf-8?B?U3JpZGhhcg==?= ASP .Net 0 12-09-2005 08:58 PM



Advertisments