empty xls after changing selectcommand datasource

Aug 27, 2012 at 10:15 AM

Hi,

Great work.

However, I've got a page with a datasource returning no records at startup.

After the users put's in some parameters for selecting records in the form, then submits and the datasource is being setup with "select xxx etc". And returning records according selected things by user.

When submitting I'm databinding the gridview to the datasource. The gridview then results data!

But the xls-button keeps offering me a empty xls.

Look's like the control doesn't change to applied changes in datasource and binded gridview?

That's a pitty!

Any clou?

regards from the Netherlands.

Aug 27, 2012 at 10:23 AM

This is what I do to apply filter to gridview:

(mysb contains full select sql-command)

Me.OracleDataSource1.SelectCommand = mySb.ToString.Replace("{0}", Me.ddlSalesArea.SelectedValue.ToString()) 
Me.GridView.DataBind()

Then the gridview shows data. But when clicking xls button, I get empty xls.

tried also after above lines: 

Me.btnExportToExcel1.GridViewID = Me.GridView.ID 
Me.btnExportToExcel1.DataBind()

 

 

Aug 27, 2012 at 11:12 AM

OK, found solution.

In the PreExport (event) I had to bind the datasource.selectcommand to the current sq-select-command (Create from parameters from form), and then gridview.databind().

this results in header + data!!!