By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,118 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Export GridView to Excel Error

P: n/a

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,

Feb 21 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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,
Feb 22 '07 #2

P: n/a
On Feb 22, 6:53 am, Mark Nelson <MarkNel...@discussions.microsoft.com>
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.

Feb 26 '07 #3

P: n/a
On Feb 26, 9:05 am, "Larry Bud" <larrybud2...@yahoo.comwrote:
On Feb 22, 6:53 am, Mark Nelson <MarkNel...@discussions.microsoft.com>
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
Feb 26 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.