Click here to Skip to main content
12,954,001 members (42,586 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Thanks to all....
I have written the code for exporting data from gridview to excel but i am getting following error...I dont know what is it...please help ...


Error 35 'controls_ExcelImportData.VerifyRenderingInServerForm(System.Web.UI.Control)': no suitable method found to override
Posted 9-Jan-13 0:51am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Add this two line onpageload(ExportToExcel is button name)
Quote:
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(this.ExportToExcel);
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

To export your grid data

public static void ExportToExcel(string strFileName, GridView dg)
   {
       try
       {
           HttpContext.Current.Response.ClearContent();
           int row = dg.Rows.Count;
           HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + strFileName + System.DateTime.Now.Hour + "_" + System.DateTime.Now.Minute + ".xls");
           HttpContext.Current.Response.ContentType = "application/excel";
           System.IO.StringWriter sw = new System.IO.StringWriter();
           HtmlTextWriter htw = new HtmlTextWriter(sw);
           dg.RenderControl(htw);
           HttpContext.Current.Response.Write(sw.ToString());
           HttpContext.Current.Response.End();
           HttpContext.Current.ApplicationInstance.CompleteRequest();
           return;
       }
       catch(Exception ex)
       {
           //ex.Message();
       }
   }


and add these lines as it is to verify rendering of control

public override void VerifyRenderingInServerForm(Control control)
   {
       /* Verifies that the control is rendered */
   }



Now In your .aspx file in <%@page .... %> add atributes

AutoEventWireup="true" EnableEventValidation="false"



this works for me hope will help you too .. happy coding :-)
  Permalink  
Comments
Aysha Patel 10-Jan-13 1:10am
   
Thanks Avinash..vry helpful code
Aysha Patel 10-Jan-13 1:13am
   
but now i come across with new problem....that is my some clients are using 2007 office and others 2003...and i hard coded extension formate in our coding like .xls or .xlsx..so what is the common coding for both extensions...thx in advance.
Tiwari Avinash 15-Jan-13 5:03am
   
make it to your lowest version like say take 2003 excel sheets extension. I think the lower version files can be opened on higher version Application. give it a try.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

This is a common error , you need to override VerifyRenderingInServerForm Method,
 
http://aspalliance.com/771


Export Gridview Data to Excel in ASP.NET[^]

Hope it helps u!!
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

try following solved example

Export Gridview Data to Excel in ASP.NET[^]

Thanks
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,464
CHill60 3,490
Maciej Los 3,123
ppolymorphe 2,020
Jochen Arndt 1,975


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100