vb.net2005中将gridview中的数据导出为EXECL

简介:

vb.net2005中将gridview中的数据导出为EXECL

author:boyi55
在按钮上定义导出EXECL事件。
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Clear()
 Response.Buffer = True
Response.Charset = "GB2312"
Response.AppendHeader("Content-Disposition", "attachment;filename=month_loginout.xls")
Response.ContentEncoding = System.Text.Encoding.UTF7
 Response.ContentType = "application/ms-excel"
Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter
Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
Me.GridView1.RenderControl(oHtmlTextWriter)
Response.Output.Write(oStringWriter.ToString)
Response.Flush()
Response.End()
End Sub
' 重载 VerifyRenderingInServerForm
 Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
End Sub
-------------------------------
出现错误:
只能在执行 Render() 的过程中调用 RegisterForEventValidation的错误提示。
解决方案:
直接在导出Execl的页面修改 
<%@ Page Language="VB"  EnableEventValidation = "false" AutoEventWireup="true"
CodeFile="ExportGridView.aspx.cs" Inherits="ExportGridView" %>









本文转自 boyi55 51CTO博客,原文链接:http://blog.51cto.com/boyi55/27297,如需转载请自行联系原作者
目录
相关文章
|
2月前
|
SQL 开发框架 前端开发
ASP.NET WEB项目中GridView与Repeater数据绑定控件的用法
ASP.NET WEB项目中GridView与Repeater数据绑定控件的用法
32 0
|
2月前
|
SQL 开发框架 .NET
ASP.NET Web——GridView完整增删改查示例(全篇幅包含sql脚本)大二结业考试必备技能
ASP.NET Web——GridView完整增删改查示例(全篇幅包含sql脚本)大二结业考试必备技能
32 0
|
开发框架 .NET 数据库连接
在ASP.NET中实现选中、编辑和删除GridView数据项
在ASP.NET中实现选中、编辑和删除GridView数据项
在ASP.NET中实现选中、编辑和删除GridView数据项