Click here to Skip to main content
11,581,515 members (63,817 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 Smile | :)
  Permalink  
Comments
Aysha Patel at 10-Jan-13 1:10am
   
Thanks Avinash..vry helpful code
Aysha Patel at 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 at 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
0 OriginalGriff 340
1 Sergey Alexandrovich Kryukov 160
2 virusstorm 114
3 Frankie-C 105
4 RyanDev 84
0 OriginalGriff 1,273
1 Sergey Alexandrovich Kryukov 895
2 Abhinav S 597
3 F-ES Sitecore 500
4 Suvendu Shekhar Giri 433


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2015
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