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.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)
    End Sub

Please guide.


Re: Display datagrid results on page while exporting to xls 80 80

When you run your export code your browser doesn't show your page at all, or is it not populating your datagrid?

I believe that you will need a pop-up to handle the export and leave your page with the datagrid.

Re: Display datagrid results on page while exporting to xls 80 80

When I run the export, my browser retains the page with the search form and the export button and only pops up the small excel "open, save, cancel" window.

Is by default supposed to happen like this?

Re: Display datagrid results on page while exporting to xls 80 80

I solved this by having a "view records" button first which shows the datagrid on page and then display another 'export to xls" button along with the datagrid which, when clicked, calls the export function -- pops up excel window etc.

Thanks adam_k for trying to help. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.