0

我正在尝试将 gridview 数据导出到 Excel。

但我Property Evaluation FailedResponse.End()

这是我的代码 - 有什么想法吗?

Private Sub ExportGridToExcel()
Try
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=NPS.xls")
Response.ContentType = "application/vnd.ms-excel"
' Remove the charset from the Content-Type header.
Response.Charset = ""

' Turn off the view state.
Me.EnableViewState = False

Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)

' Get the HTML for the control.
gvNPSResults.RenderControl(hw)
' Write the HTML back to the browser.
Response.Write(tw.ToString())
' End the response.

HttpContext.Current.ApplicationInstance.CompleteRequest()
Response.End()
Catch ex As Exception
'Throw ex
End Try
End Sub
4

1 回答 1

0

再次尝试替换您的代码

HttpContext.Current.ApplicationInstance.CompleteRequest();

Response.End();

经过

 Response.Flush();
 Response.Close();
于 2012-09-30T04:34:27.503 回答