Click here to Skip to main content
16,020,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

Add this two line onpageload(ExportToExcel is button name)
Quote:
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(this.ExportToExcel);
 
Share this answer
 
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

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



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

VB
AutoEventWireup="true" EnableEventValidation="false"



this works for me hope will help you too .. happy coding :-)
 
Share this answer
 
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.
VB
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!!
 
Share this answer
 
try following solved example

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

Thanks
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900