PreExport problem

Feb 14, 2009 at 9:57 AM
Edited Feb 14, 2009 at 10:02 AM

Excel file does'nt match the gridview

When the page is called, the sqldatasource is empty, the gridview also. 
The export button is disabled.
Then I load the data into the gridview, the export button becomes enabled and i export them.
The routine "PreExport" is called but the excel file is empty except the columns header.

Any idea ?



Here is my code :

  Protected Sub Selection_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Selection.Click
        // load data into gridview
        SqlDataSource1.SelectCommand = "Select C_NUMERO FROM Marketing"
        gv.DataSourceID = "SqlDataSource1"
        gv.AllowSorting = "True"
        gv.AutoGenerateColumns = "True"
    End Sub

    Protected Sub ExportToExcel1_PreExport(ByVal sender As Object, ByVal e As System.EventArgs) Handles ExportToExcel1.PreExport  
        ExportToExcel1.ExportFileName = "test.xls"  // works fine- result : test + timestamp
        ExportToExcel1.GridViewID = "gv"
    End Sub


       // Return empty recordset
       <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CSPersonnel %>"
        ProviderName="<%$ ConnectionStrings:CSPersonnel.ProviderName %>"  />       
     <RK:ExportToExcel ID="ExportToExcel1" runat="server" ApplyStyleInExcel="True" Charset="utf-8"
            ContentEncoding="windows-1250" EnableHyperLinks="True"
            IncludeTimeStamp="True" PageSize="All" Text="Export To Excel" />
       // Empty grid    
        <asp:GridView ID="gv" runat="server"></asp:GridView>

       // Button to load the data       
      <asp:Button ID="Selection" runat="server" Text="Select />

Jan 20, 2010 at 3:43 PM

I'm having the same issue. I populate the gridview on the fly along with the datasource.

Can this be resolved?

Jan 20, 2010 at 3:52 PM

Figured it out... needed to run the PreExport function to refresh my gridview.

Thanks to this forum I found my answer.