当用户点击按钮时,我正在尝试根据gridview的内容创建一个csv文件。但是,当单击按钮时,我不断地通过服务器重置Connection。提前谢谢。
Protected Sub btnExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExport.Click
Try
Dim out As IO.TextWriter = Response.Output
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.Buffer = True
Response.AddHeader("content-disposition", "attachment;filename=SearchResults.csv")
Response.Charset = ""
Response.ContentType = "application/text"
gvFiles.AllowPaging = False
gvFiles.DataBind()
Me.EnableViewState = False
'Bind DataTable to GridView
'Search() method returns a DataTable of search results
'gvFiles.DataSource = Search()
'gvFiles.DataBind()
'String builder class to add row data
Dim sb As New StringBuilder()
For k As Integer = 0 To gvFiles.Columns.Count - 1
'add separator
sb.Append(gvFiles.Columns(k).HeaderText & ",")
Next
'append(New line)
sb.Append(vbCrLf)
'Get Rows
For i As Integer = 0 To gvFiles.Rows.Count - 1
'Get columns
For k As Integer = 0 To gvFiles.Columns.Count - 1
'add separator
sb.Append(gvFiles.Rows(i).Cells(k).Text & ",")
Next
'append new line
sb.Append(vbCrLf)
Next
out.Write(sb.ToString())
out.Flush()
'out.Close()
Response.End()
Catch ex As Exception
Response.Write("Unable to generate File" & ex.ToString())
End Try
End Sub
答案 0 :(得分:0)
我找到了答案,我不得不编辑web.config连接超时等,因为事实证明它生成了如此大的.csv文件,连接超时。