解决gridview的excel导出问题
2005-12-30 18:11
393 查看
以前datagrid导出为excel,只需如下代码:
Response.Clear();
Response.AddHeader("content-disposition",
"attachment;filename=FileName.xls");
Response.Charset =
"";
// If you want
the option to open the Excel file without saving than
// comment out
the line below
//
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType =
"application/vnd.xls";
System.IO.StringWriter
stringWrite = new
System.IO.StringWriter();
System.Web.UI.HtmlTextWriter
htmlWrite = new
HtmlTextWriter(stringWrite);
gvMaster.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
现在改成gridview后,以上代码会提示异常错误,经网上搜索,解决方案如下
1、在导出界面中重载
public override void VerifyRenderingInServerForm(Control control)
{
//base.VerifyRenderingInServerForm(control);
}
2、在web.config中修改<pages enableEventValidation ="false" ></pages>
或
<%@ Page Language="C#" EnableEventValidation = "false" AutoEventWireup="true"
CodeFile="ExportGridView.aspx.cs" Inherits="ExportGridView" %>
3、现在可以正常导出了。
Response.Clear();
Response.AddHeader("content-disposition",
"attachment;filename=FileName.xls");
Response.Charset =
"";
// If you want
the option to open the Excel file without saving than
// comment out
the line below
//
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType =
"application/vnd.xls";
System.IO.StringWriter
stringWrite = new
System.IO.StringWriter();
System.Web.UI.HtmlTextWriter
htmlWrite = new
HtmlTextWriter(stringWrite);
gvMaster.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
现在改成gridview后,以上代码会提示异常错误,经网上搜索,解决方案如下
1、在导出界面中重载
public override void VerifyRenderingInServerForm(Control control)
{
//base.VerifyRenderingInServerForm(control);
}
2、在web.config中修改<pages enableEventValidation ="false" ></pages>
或
<%@ Page Language="C#" EnableEventValidation = "false" AutoEventWireup="true"
CodeFile="ExportGridView.aspx.cs" Inherits="ExportGridView" %>
3、现在可以正常导出了。
相关文章推荐
- GridView导出数据到excel数字变为科学记数法的问题的解决办法
- GridView导出数据到excel数字变为科学记数法的问题的解决办法
- gridview导出Excel解决方案整理(解决乱码问题)
- 解决gridview导出到excel中汉字出现乱码的问题
- Gridview 导出excel,解决了只能导出当前页的问题
- 解决SharePoint中GridView导出Excel按钮的问题
- 解决C# 导出gridview中的数据到excel 时, 全数字时 0 被去掉的问题
- asp.net中将gridview数据导出成Excel问题解决
- 解决SharePoint中GridView导出Excel按钮的问题
- 将GridView中的数据导出到Excel中下载并且解决乱码的问题
- 关于GridView导出Excel的一些问题(采用Ajax出现的的问题及解决方法)
- 解决gridview导出到excel中汉字出现乱码的问题
- 解决SharePoint中GridView导出Excel按钮的问题
- 如何解决gridview以及table导出Excel的科学计数法问题
- 将GridView中的数据导出到Excel中下载并且解决乱码的问题
- 解决AspNet中DataGrid GridView等列表控件导出Excel长数字显示成科学计数法的问题
- Asp.net Gridview 导出到Excel【解决编码乱码问题】
- GridView导出数据到excel数字变为科学记数法的问题的解决办法
- 扩展gridview的导出excel功能乱码问题的解决
- 扩展gridview的导出excel功能乱码问题的解决