Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
215
Export to Excel only exports column headers, no data.
posted

I'm calling a stored procedure, filling a datatable with the results, then binding the webdatagrid to the datatable.  When I export the webdatagrid to Excel, the column headers are exported but no data.  Here are the relevant pieces of code:

Dim selectionString As String
       selectionString = "EXEC NamePhraseSearch '" + BuildParameter() + "'"
 
       SqlDataSource1.SelectCommandType = SqlDataSourceCommandType.Text
       SqlDataSource1.SelectCommand = selectionString
       'SqlDataSource1.Select(DataSourceSelectArguments.Empty)
 
       Dim connectionstring As String = SqlDataSource1.ConnectionString
       Using cnn As New Data.SqlClient.SqlConnection(connectionstring)
           cnn.Open()
           Using dad As New Data.SqlClient.SqlDataAdapter(selectionString, cnn)
               dad.SelectCommand.CommandTimeout = 0
               dad.Fill(dtb)
           End Using
           cnn.Close()
       End Using
 
       webGridResults.DataSource = dtb
       webGridResults.DataBind()
--This results in the grid being populated with the results from the stored procedure in the form of the datatable.
--Then to export to excel:
       WebExcelExporter1.DataExportMode = DataExportMode.AllDataInDataSource
       WebExcelExporter1.DownloadName = "ListingsSummary"
       WebExcelExporter1.Export(webGridResults)
When I open the excel file that is downloaded there are only Column headers, no data.
Please assist me with this issue.