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

Problem exporting grid with virtual paging

2 Answers 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 12 Sep 2014, 08:13 PM
I'm trying to export a radgridview to Excel.  When I was using regular paging, everything was working fine but since I switched to virtual paging, I can only export the current page to excel instead of the entire grid's contents.  I've added the following code to the ItemCommand handler:
case RadGrid.ExportToExcelCommandName:
                {
                    rgResult.PageSize = rgResult.MasterTableView.VirtualItemCount;
                    rgResult.ExportSettings.ExportOnlyData = true;
                    rgResult.ExportSettings.IgnorePaging = true;
                    rgResult.ExportSettings.OpenInNewWindow = true;                     
                    rgResult.MasterTableView.ExportToExcel();
                }
                break;
This causes an "System.ArgumentOutOfRangeException" exception when trying to set the page size equal to the grid's virtual item count. Probably because the VirtualItemCount is equal to 0.

Thanks!

2 Answers, 1 is accepted

Sort by
0
Accepted
Konstantin Dikov
Telerik team
answered on 17 Sep 2014, 01:59 PM
Hello Tom,

I have examined the code snippet in your post and you are correct that the reason for the exception is due to the fact that the VirtualItemCount is 0.

Nevertheless, for achieving the desired result for exporting all pages with enabled Virtualization, you should disable the virtualization when the ExportToExcelCommandName is fired.

Following is a modified version of your code, exporting all items as expected:
if (e.CommandName == RadGrid.ExportToExcelCommandName)
{
    //rgResult.PageSize = rgResult.MasterTableView.VirtualItemCount;
    rgResult.ExportSettings.ExportOnlyData = true;
    rgResult.ClientSettings.Virtualization.EnableVirtualization = false;
    rgResult.ExportSettings.IgnorePaging = true;
    rgResult.ExportSettings.OpenInNewWindow = true;
    rgResult.MasterTableView.ExportToExcel();
}

Please let me know if the export works correctly on your end too.
 

Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Tom
Top achievements
Rank 1
answered on 18 Sep 2014, 08:37 PM
It worked great, thank you.  
(I could've sworn I tried that...)
Tags
Grid
Asked by
Tom
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Tom
Top achievements
Rank 1
Share this question
or