从gridview导出数据到excel时出错 [英] Getting Error While exporting data from gridview to excel...

查看:82
本文介绍了从gridview导出数据到excel时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢所有人....

我已经编写了将数据从gridview导出到excel的代码,但我收到了以下错误...我不知道它是什么...请帮助...





错误35''controls_ExcelImportData.VerifyRenderingInServerForm(System.Web.UI.Control)'':找不到合适的方法覆盖

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

推荐答案

在onpageload上添加这两行(ExportToExcel是按钮名称)

Add this two line onpageload(ExportToExcel is button name)
引用:

ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);

scriptManager.RegisterPostBackControl(this.ExportToExcel);

ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(this.ExportToExcel);


导出网格数据



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();
       }
   }





并添加这些行以验证控件的呈现< br $> b $ b



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

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







现在在<%@ page ....%>中的.aspx文件中添加属性






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

AutoEventWireup="true" EnableEventValidation="false"

< br $> b $ b



这对我有用希望对你有帮助..编码快乐: - )




this works for me hope will help you too .. happy coding :-)


This is a common error , you need to override VerifyRenderingInServerForm Method,

http://aspalliance.com/771





将Gridview数据导出到ASP.NET中的Excel [ ^ ]



希望它能帮到你!!



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

Hope it helps u!!


这篇关于从gridview导出数据到excel时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆