我正在尝试使用asp.net将gridview数据导出到csv文件中。我使用了以下从网站获得的代码,它成功下载了一个csv文件,但没有内容,这意味着整个csv文件都是空的。
Response.ClearContent()
Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", "Data.csv"))
Response.ContentType = "application/text"
GridView1.AllowPaging = False
GridView1.DataBind()
Dim strbldr As New StringBuilder()
For i As Integer = 0 To GridView1.Columns.Count - 1
'separting header columns text with comma operator
strbldr.Append(GridView1.Columns(i).HeaderText + ","c)
Next
'appending new line for gridview header row
strbldr.Append(vbLf)
For j As Integer = 0 To GridView1.Rows.Count - 1
For k As Integer = 0 To GridView1.Columns.Count - 1
'separating gridview columns with comma
strbldr.Append(GridView1.Rows(j).Cells(k).Text + ","c)
Next
'appending new line for gridview rows
strbldr.Append(vbLf)
Next
Response.Write(strbldr.ToString())
Response.[End]()
我该怎么办?
提前致谢。
答案 0 :(得分:0)
似乎与Trying to export asp.net gridview to a .csv file
相同的问题GridView1.AllowPaging = False
GridView1.DataBind()
线条是否会导致问题,应该删除。