Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 84751

Problem exporting Radgrid to Excel

$
0
0

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

 


Viewing all articles
Browse latest Browse all 84751

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>