GridView导出到Excel 为什么有时候导出的是

1285189390 2008-01-13 06:41:24
System.Web.HttpContext.Current.Response.Clear()
System.Web.HttpContext.Current.Response.Buffer = True
System.Web.HttpContext.Current.Response.Charset = "GB2312"
Dim s As String
s = "attachment;filename=" + HttpUtility.UrlEncode(strFileName, System.Text.Encoding.UTF8)
Dim aType As String
Select Case aFileType
Case 0 'excle
s = s + ".xls"
aType = "application/ms-excel"
Case 1 'word
s = s + ".doc"
aType = "application/ms-word"
Case 2 'TXT 暂时不用
s = s + ".txt"
aType = "application/ms-txt"
Case 3 'html
s = s + ".html"
aType = "application/ms-html"
End Select
System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", Trim(s))
System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312")
application/ms-txt、application/ms-html 或其他浏览器可直接支持文档
System.Web.HttpContext.Current.Response.ContentType = aType
Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter
Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
aGridView.AllowPaging = False
aGridView.AllowSorting = False
aGridView.DataBind()
aGridView.RenderControl(oHtmlTextWriter)
System.Web.HttpContext.Current.Response.Output.Write(oStringWriter.ToString)
System.Web.HttpContext.Current.Response.Flush()
System.Web.HttpContext.Current.Response.End()

----------------
用上述代码导出有按钮列的GridView,有的页面成功,有的页面导出后却是<div> <div>
为什么呢?
GridView的数据源是用的SqlDataSource,但SqlDataSource.SelectCommand在Page_Load中给的。
有遇到同样问题的人吗?
...全文
410 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
NS21113513 2012-03-17
  • 打赏
  • 举报
回复
我也遇到了怎么解决
christ 2011-12-12
  • 打赏
  • 举报
回复
view可以吗
试试~
isabel_cui 2011-02-23
  • 打赏
  • 举报
回复
我也有同样的问题 但我是用了masterpage的,不知道是不是因为这个
楼外楼 2008-01-13
  • 打赏
  • 举报
回复
你的问题是出现空值了吧

会不会是取值方法不对呢,

我用C#实现和你一样的工作的时候,

是直接从Gridview的dataSource去取值

我直接用DataSource的View

没有遇到过这种问题
deepinnet 2008-01-13
  • 打赏
  • 举报
回复
aGridView.DataBind() 你自己写的方法吗?
这里要写自己绑的方法.解决问题记得给分
1285189390 2008-01-13
  • 打赏
  • 举报
回复
up bu self
1285189390 2008-01-13
  • 打赏
  • 举报
回复
up by self

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧