Export GridView to Excel Error

G

Guest

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,
 
G

Guest

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>
 
L

Larry Bud

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.
 
L

Larry Bud

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top