IT Community - Software Programming, Web Development and Technical Support

Exporting GridView to Excel

This is a discussion on Exporting GridView to Excel within the ASP and ASP.NET Programming forums, part of the Web Development category; Hi,When i tried to export the data from the gridview to excel I got the following error Could anyone ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 03-26-2008, 02:11 AM
shaalini shaalini is offline
D-Web Analyst
 
Join Date: Apr 2007
Posts: 342
shaalini is on a distinguished road
Default Exporting GridView to Excel

Hi,When i tried to export the data from the gridview to excel I got the following error
Could anyone help me out

Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.

my form tag contains runat ="server"
__________________
Shaalini.S
Be the Best of Whatever you are...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-26-2008, 02:16 AM
bluesky bluesky is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 201
bluesky is on a distinguished road
Default Re: Exporting GridView to Excel

This is pretty confusing, since your GridView is already inside the form tags and also contains the runat = server attribute. You can easily resolve this error by adding the following lines.

public override void VerifyRenderingInServerForm(Control control)
{
/* Confirms that an HtmlForm control is rendered for the specified ASP.NET
server control at run time. No code Required here */

}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-26-2008, 02:18 AM
shaalini shaalini is offline
D-Web Analyst
 
Join Date: Apr 2007
Posts: 342
shaalini is on a distinguished road
Default Re: Exporting GridView to Excel

Hi blue sky,
I have tried with your following code but now i m getting following error
RegisterForEventValidation can only be called during Render();
__________________
Shaalini.S
Be the Best of Whatever you are...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-26-2008, 02:21 AM
bluesky bluesky is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 201
bluesky is on a distinguished road
Default Re: Exporting GridView to Excel

Hi shaalini,
There are a couple of approches that can be taken to allow for a control to be programmatically rendered without raising the event validation-related exception. The simplest approach is to simply disable event validation for the page. This can be done by setting the EnableEventValidation attribute in the <% @Page %> directive to False:
<% @Page EnableEventValidation="False" ... %>
If you are using the base Page class technique to override the Page class's VerifyRenderingInServerForm() method, you can always override the EnableEventValidation property there, instead.

The other option is to leave the event validation feature enabled, but just wait to programmatically render the control until the Render stage. By doing this, when the control registers for event validation it will be in the Render stage and so the "RegisterForEventValidation can only be called during Render()" exception won't be raised. To accomplish this, you'll need to set some flag in the Button's Click event handler (or wherever you decide to programmatically render the control).
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-26-2008, 02:23 AM
shaalini shaalini is offline
D-Web Analyst
 
Join Date: Apr 2007
Posts: 342
shaalini is on a distinguished road
Default Re: Exporting GridView to Excel

Hi bluesky ,

Thanx.It works fine.
__________________
Shaalini.S
Be the Best of Whatever you are...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView.DataBind not working rrrajesh84in ASP and ASP.NET Programming 1 03-21-2008 10:01 PM
Which is the best among DataList,Repeater and GridView and Why? poornima ASP and ASP.NET Programming 2 03-14-2008 08:44 PM
GridView Item Tempalte Problem shaalini C# Programming 0 01-29-2008 09:11 PM
"POST" large amount of data using SendAndLoad (Exporting JPG/JPEG) aramesh Flash Actionscript Programming 2 12-28-2007 02:42 AM
How to add mouseover function to Gridview..? kingmaker C# Programming 1 07-20-2007 12:40 AM


All times are GMT -7. The time now is 08:48 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0