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

Please guide.

Thanks,
Michelle

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.

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?

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.