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

Exporting Paged Data

6 Answers 119 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Phi
Top achievements
Rank 1
Phi asked on 15 Dec 2010, 08:34 PM
Hello, 

I am trying to export all items (several thousands rows) instead of the paged view from a gridview. The gridview is bound to a domain data source and a data pager. I know I must first set the PageSize of the domain data source to 0 before I call Export. Am I missing something here? Any help is greatly appreciated.

int originalPageSize = this.transactionDomainDataSource.PageSize;

using (Stream stream = dialog.OpenFile())
{
this.transactionDomainDataSource.PageSize = 0;

GridViewExportOptions exportOptions = new GridViewExportOptions();
exportOptions.Format = ExportFormat.Html;
exportOptions.ShowColumnFooters = true;
exportOptions.ShowColumnHeaders = true;
exportOptions.ShowGroupFooters = true;
exportOptions.Items = (IEnumerable) this.myPager.PagedSource;

this.myGridView.Export(stream, exportOptions);
}

this.transactionDomainDataSource.PageSize = originalPageSize;

                int originalPageSize = this.transactionDomainDataSource.PageSize;    

                using (Stream stream = dialog.OpenFile())
                {
                    this.transactionDomainDataSource.PageSize = 0; 

                    GridViewExportOptions exportOptions = new GridViewExportOptions();
                    exportOptions.Format = format;                    
                    exportOptions.ShowColumnFooters = true;
                    exportOptions.ShowColumnHeaders = true;
                    exportOptions.ShowGroupFooters = true;                    
                    exportOptions.Items = (IEnumerable)this.radPager.PagedSource;
                                                      
                    this.dgrTransactions.Export(stream, exportOptions);                    
                }

                this.transactionDomainDataSource.PageSize = originalPageSize;
                int originalPageSize = this.transactionDomainDataSource.PageSize;    

                using (Stream stream = dialog.OpenFile())
                {
                    this.transactionDomainDataSource.PageSize = 0; 

                    GridViewExportOptions exportOptions = new GridViewExportOptions();
                    exportOptions.Format = format;                    
                    exportOptions.ShowColumnFooters = true;
                    exportOptions.ShowColumnHeaders = true;
                    exportOptions.ShowGroupFooters = true;                    
                    exportOptions.Items = (IEnumerable)this.radPager.PagedSource;
                                                      
                    this.dgrTransactions.Export(stream, exportOptions);                    
                }

                this.transactionDomainDataSource.PageSize = originalPageSize;
                int originalPageSize = this.transactionDomainDataSource.PageSize;    

                using (Stream stream = dialog.OpenFile())
                {
                    this.transactionDomainDataSource.PageSize = 0; 

                    GridViewExportOptions exportOptions = new GridViewExportOptions();
                    exportOptions.Format = format;                    
                    exportOptions.ShowColumnFooters = true;
                    exportOptions.ShowColumnHeaders = true;
                    exportOptions.ShowGroupFooters = true;                    
                    exportOptions.Items = (IEnumerable)this.radPager.PagedSource;
                                                      
                    this.dgrTransactions.Export(stream, exportOptions);                    
                }

                this.transactionDomainDataSource.PageSize = originalPageSize

6 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 16 Dec 2010, 08:27 AM
Hi,

 I believe that with DomainDataSource you will need to wait data to be loaded and after this you will able to export all items. 

All the best,
Vlad
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Phi
Top achievements
Rank 1
answered on 17 Dec 2010, 09:12 PM
Is there something else I need to include in the code for this? Thanks.
0
Vlad
Telerik team
answered on 20 Dec 2010, 09:52 AM
Hi,

 When you change PageSize for the DomainDataSource this will invoke automatically new request to the server and once the data are loaded (LoadedData event) you can export them. 

Regards,
Vlad
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Half
Top achievements
Rank 1
answered on 10 Jun 2011, 11:59 AM
Adding on this discussion:
 So to export the data we set PageSize = 0, which forces the whole data set to be loaded.
In my application, this leads my application to throw WCF Communication errors, because of messages exceeding allowed limits (which I can't change). My implementations fetches data in the PageChanged event.

How can I implement the export method to force paging the pagedcollectionview and thus fetch results in smalller chunks?

0
Ivan Ivanov
Telerik team
answered on 16 Jun 2011, 08:58 AM
Hello Half,

 Unfortunately, as for me, your scenario goes beyond the framework's limitations. The only solution that comes to my mind, different from keeping the data on the client, is to load the data from the same DomainContext in several parts and assign it as an ItemsSource of a second RadGridView that is not added to the visual tree. Then you would be able to export it, instead of the displayed RadGridView. I know that this solution is rather inconvenient, so please let me know if this approach will fit your needs.

Greetings,
Ivan Ivanov
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Marcel
Top achievements
Rank 1
answered on 21 May 2013, 08:53 PM
Hi,

I found this worked for me ...
private void ExportButton_Click(object sender, RoutedEventArgs e)
{
    string extension = "xls";
    SaveFileDialog dialog = new SaveFileDialog()
    {
        DefaultExt = extension,
        Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Excel"),
        FilterIndex = 1
    };
    if (dialog.ShowDialog() == true)
    {
        radDataPager.PageSize=999999;
        using (Stream stream = dialog.OpenFile())
        {
            ResultsRadGridView.Export(stream,
             new GridViewExportOptions()
             {
                 Format = ExportFormat.Html,
                 ShowColumnHeaders = true,
                 ShowColumnFooters = true,
                 ShowGroupFooters = false,
             });
        }
        radDataPager.PageSize = 100;
    }
}
Tags
GridView
Asked by
Phi
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Phi
Top achievements
Rank 1
Half
Top achievements
Rank 1
Ivan Ivanov
Telerik team
Marcel
Top achievements
Rank 1
Share this question
or