This is a migrated thread and some comments may be shown as answers.

Problem exporting Radgrid to Excel

1 Answer 116 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alberto
Top achievements
Rank 1
Alberto asked on 18 Dec 2015, 10:46 PM

Hello guys i need your help

I have two sqlDatasources : 

<asp:SqlDataSource ID="sqlLookupDepartments" runat="server" ConnectionString="<%$ ConnectionStrings:WEBCMSConnectionString %>" SelectCommand="SELECT top 5 * FROM [tblLookupDepartments]"></asp:SqlDataSource>

<asp:SqlDataSource ID="sqlDepartments" runat="server" ConnectionString="<%$ ConnectionStrings:WEBCMSConnectionString %>"></asp:SqlDataSource>

 

First one has assigned the SelectCommand, the second will be assigned programmatically onPageLoad event :

 

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            var sqlQuery = "SELECT top 5 * FROM [tblLookupDepartments]";
            sqlDepartments.SelectCommand = sqlQuery;
            sqlDepartments.DataBind();
            RadGrid2.Rebind();  
        }

    }

 

Then i added funcionallity to export to excel to Radgrid 1 using the first sqlDatasource, this is working without any problems

 

        <telerik:RadGrid ID="RadGrid1" runat="server" CellSpacing="-1" Culture="es-ES" DataSourceID="sqlLookupDepartments" GridLines="Both" GroupPanelPosition="Top">
            <ExportSettings IgnorePaging="true" Excel-Format="ExcelML" ExportOnlyData="true" OpenInNewWindow="true"></ExportSettings> 
            <MasterTableView AutoGenerateColumns="true" DataKeyNames="department_id" DataSourceID="sqlLookupDepartments" CommandItemDisplay="Top">
             <CommandItemSettings ShowExportToExcelButton="True" ShowAddNewRecordButton="false" ShowRefreshButton="false" />
                <Columns>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>

 

But when im tryng to do the same on Radgrid2 using the second sqlDatasource

 

        <telerik:RadGrid ID="RadGrid2" runat="server" CellSpacing="-1" Culture="es-ES" DataSourceID="sqlDepartments" GridLines="Both" GroupPanelPosition="Top" OnItemCommand="RadGrid2_ItemCommand">
            <ExportSettings IgnorePaging="true" Excel-Format="ExcelML" ExportOnlyData="true" OpenInNewWindow="true"></ExportSettings> 
            <MasterTableView AutoGenerateColumns="true" DataKeyNames="department_id" DataSourceID="sqlDepartments" CommandItemDisplay="Top">
             <CommandItemSettings ShowExportToExcelButton="True" ShowAddNewRecordButton="false" ShowRefreshButton="false" />
                <Columns>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>

 

This radgrid2 have a ttached the OnItemCommand event 

 

    protected void RadGrid2_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        RadGrid2.ExportSettings.Excel.Format = GridExcelExportFormat.Biff;
        RadGrid2.ExportSettings.IgnorePaging = true;
        RadGrid2.ExportSettings.ExportOnlyData = true;
        RadGrid2.ExportSettings.OpenInNewWindow = true;
        RadGrid2.MasterTableView.ExportToExcel();
    }

 

After clickind on teh export to Excel button, it downloads the excel file , but its empty.

 

Please i will appreciate your help regarding this issue.

 

Thank you very much.

 

Regards,

Alberto

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 23 Dec 2015, 03:49 PM
Hello Alberto,

Could you verify that you are not using DataBind() or Rebind() to bind the grid initially? Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Exporting, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
Declarative DataSource
Programmatic Data Binding


Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Alberto
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or