1
我有一个gridvidew(GV2)。我希望用户能够将此GridView的内容导出到Excel电子表格以供离线处理。将gridview内容导出为excel电子表格
这里是我的子程序:
Protected Sub ExcelButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ExcelButton.Click
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim stringWriter As New System.IO.StringWriter()
Dim htmlWriter As New System.Web.UI.HtmlTextWriter(stringWriter)
GV2.RenderControl(htmlWriter)
Response.Write(stringWriter.ToString())
Response.End()
End Sub
在点击ExcelButton我得到的错误消息:类型的GridView'的
控制“GV2”必须放在一个表单标签内有RUNAT =服务器。
控制GV2其实里面:
<form id="form1" runat="server"></form>
感谢您的帮助。我添加了上面的代码,现在得到:RegisterForEventValidation只能在Render()中调用; – Phil 2010-02-25 10:56:25
我通过关闭事件验证来解决这个问题.....通过在@page指令中添加EnableEventValidation =“false”...这是否存在潜在的危险? – Phil 2010-02-25 11:07:42
@Phil,我假设你只关闭该特定页面的事件验证,则需要确保该页面的回发事件不会被劫持以执行非法或不需要的操作。 – 2010-02-25 11:52:09