我正在尝试将gridview数据导出到Excel。
但我在Property Evaluation Failed
Response.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
答案 0 :(得分:0)
再次尝试替换您的代码
HttpContext.Current.ApplicationInstance.CompleteRequest();
Response.End();
通过
Response.Flush();
Response.Close();