I have a working code that exports the datagrid into XLS. However, the datagrid results does not show on my aspx (html) page. It only shows on the page when I comment out the part that exports it to xls. I am not sure whether it should show by default when exporting.
Basically, what I want to have is when I click my export button, it should display the datagrid on the page as well as popup an excel "open, save, cancel" window for the export.
Here is my function for referece:
Public Sub Convert(ByVal ds As DataSet, ByVal Response As HttpResponse) Dim attachment As String = "attachment; filename= ExportPRFs_" & Today() & ".xls" Response.Clear() Response.Charset = "" Response.AddHeader("content-disposition", attachment) Response.ContentType = "application/vnd.ms-excel" Dim stringWrite As System.IO.StringWriter = New System.IO.StringWriter() Dim htmlWrite As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(stringWrite) Dim dg As System.Web.UI.WebControls.DataGrid = New System.Web.UI.WebControls.DataGrid() dg.DataSource = ds.Tables(0) dg.DataBind() dg.RenderControl(htmlWrite) Response.Write(stringWrite.ToString()) Response.End() End Sub