473,783 Members | 2,545 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Ad d(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.RenderCo ntrol(htmlWrite );

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

Thanks,

Feb 21 '07 #1
3 10121
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" ContentPlaceHol derID="ContentP laceHolder1"
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.Ad d(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.RenderCo ntrol(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...@dis cussions.micros oft.com>
wrote:
I have aGridViewcontro lin page called eventslisting which is inheriting
from a MasterPage. The normal code to export toGridViewdoes not work and
gives me an error - "ControloftypeG ridViewmustbepl acedinsideformt ag
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=serv er
attribute to it and then added thegridviewto it programatically as
frm.Controls.Ad d(dgTemp);
But I get the same error - "ControloftypeG ridViewmustbepl acedinside
formtagwithruna t = server". when I perform the step
dgTemp.RenderCo ntrol(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" ContentPlaceHol derID="ContentP laceHolder1"Run at="Server">
<asp:GridViewID ="GridView1"run at="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...@y ahoo.comwrote:
On Feb 22, 6:53 am, Mark Nelson <MarkNel...@dis cussions.micros oft.com>
wrote:


I have aGridViewcontro lin page called eventslisting which is inheriting
from a MasterPage. The normal code to export toGridViewdoes not work and
gives me an error - "ControloftypeG ridViewmustbepl acedinsideformt ag
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=serv er
attribute to it and then added thegridviewto it programatically as
frm.Controls.Ad d(dgTemp);
But I get the same error - "ControloftypeG ridViewmustbepl acedinside
>formtagwithrun at = server". when I perform the step
dgTemp.RenderCo ntrol(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" ContentPlaceHol derID="ContentP laceHolder1"Run at="Server">
<asp:GridViewID ="GridView1"run at="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 VerifyRendering InServerForm(By Val 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
5650
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 'gvSearch' of type 'GridView' must be placed inside a form tag with runat=server.
0
1877
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 Gridview to Excel that is used in a content section of a master page?
5
2820
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 Excel. How can I prevent this from happening ?. I need to value to be in Excel as it is displayed in the Gridview (on the web page).
0
2572
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):- But when I run the code, it raise an error -> Control 'ctl02_GridView1' of type 'GridView' must be placed inside a form tag with runat=server" My Listdata.aspx page are place under MasterPage.aspx, which is inside Contentplace holder. how to...
6
6484
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 cells in the row_databound event, and now I nedd to do a excel export of the gridview exactly as is showed in the browser, but al the examples and thigs I've tried don't send the cell color to excel and now I think if I can read the gridview...
1
3364
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 problem is, the image won't display unless I'm connected to the Internet or if I use a relative path and have the image stored relative to the excel file. Is it possible to "embed" the image from the gridview into the excel workbook so I could give...
0
463
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: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common cause for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is...
3
5212
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 excel on every way : 1. I disabled the allowpaging in gridview and got and error messages like : System.OutOfMemoryException Was Thrown 2. My idea is to store row in gridview to virtable per pages. I create virtable as Table. Added row to virtable...
11
12624
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 25000 records) to excel How to solve this ?
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10315
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.