2012-06-29 62 views
0

我想導出gridview數據到Excel。屬性評估失敗錯誤,同時導出Gridview到Excel

但我在Response.End()

這是我的代碼得到錯誤Property Evaluation Failed - 任何想法?

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

再次嘗試通過

Response.Flush(); 
Response.Close(); 
更換你的代碼

HttpContext.Current.ApplicationInstance.CompleteRequest(); 

Response.End();