473,396 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Export GridView to Excel Error


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
3 10089
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Not Me | last post by:
Hi, I'm trying to export from a gridview control, to an excel file using code intended for a datagrid control (it's all over the web, can post if requested) I get the error. Control...
0
by: CSharpguy | last post by:
I have code that exports a grid view to Excel, but when I put that code in my content page of my master pages, I get an error, gridview must be in a <form runat=servertag. So how can I export a...
5
by: karthick | last post by:
Hi, I am exporting a Gridview to Excel and it works fine without any issues. But as one of the field holds values such as "71646E100" it gets converted to: "7.16E+104" (like a formula) in...
0
by: johnlim20088 | last post by:
Hi, Hi someone can help me on this? Currently I have a Listdata.aspx page with datagrid, I wish to export my datagrid content to excel with following code ( with button export click event):- ...
6
by: Sergio E. | last post by:
Hi, I'm looking for information about gridview's cell properties... I've the following case: one gridview with alternatirg row style and normalrowstyle, 3 o 4 custom styles that are applied to...
1
by: edwinparker | last post by:
Hi, I'm trying to convert a gridview to an excel report and have one small hang up. So far I've been able to create my gridview and export it to excel ok, but in my gridview I have an image. The...
0
by: Mike | last post by:
On my page I'm using an updatepanel, updateProgress, and a ModalProgress, everything works great But when I try to export my GridView to excel I'm getting the following error message: ...
3
by: ulai | last post by:
Thanks for your help. It really help to solve my work. But now i have a bigger problem : I had more than 65535 records in gridview divide by 10/pages. And when i tried to export the gridview in...
11
by: ulai | last post by:
Hello everyone, I want to export GridView (25000 records) to Excel. But i got an error message like : System.OutOfMemoryException was Thrown. But i need to export the records (even more than...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.