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

Export to Excel with RadDataPager and RadDataServiceDataSource

3 Answers 32 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 21 Dec 2011, 03:54 PM
Hello,

I am trying to export the contents of my RadGridView (including all pages) to Excel.  For some reason, it is only exporting the current page.  I tried to set the RadDataPager PageSize property to 0 but that doesnt work.  I figure it may be something that I am missing that has to be done that is specific to having RadDataServiceDataSource as my source of data.

See code below:

private void exportButton_Click(object sender, RoutedEventArgs e)
{
 
    string extension = "xls";
    string selectedItem = "Excel";
    ExportFormat format = ExportFormat.Html;
 
    SaveFileDialog dialog = new SaveFileDialog();
    dialog.DefaultExt = extension;
    dialog.Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, selectedItem);
    dialog.FilterIndex = 1;
    int originalPageSize = radDataPager1.PageSize;
    int originalPageIndex = radDataPager1.PageIndex;
    if (dialog.ShowDialog() == true)
    {
        using (Stream stream = dialog.OpenFile())
        {
            radDataPager1.PageSize = 0;
            GridViewExportOptions options = new GridViewExportOptions();
            options.Format = format;
            options.ShowColumnHeaders = true;
 
            options.Encoding = System.Text.Encoding.UTF8;
            RadGridView1.Export(stream, options);
        }
        radDataPager1.PageSize = originalPageSize;
        radDataPager1.PageIndex = originalPageIndex;
    }

Thanks,
Jorge

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 21 Dec 2011, 04:27 PM
Hello Jorge,

If you want to export server-side data you need to download the entire collection to the client. I suggest you to use Telerik Reporting instead to export the data on the server and download the exported output. 

Regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Nick
Top achievements
Rank 1
answered on 21 Dec 2011, 04:37 PM
Vlad,

Since I already have everything I need in the Grid,  I would rather fix this code to export everything as opposed to use Telerik reporting.  Can you help?

Thanks,
Jorge
0
Vlad
Telerik team
answered on 21 Dec 2011, 04:42 PM
Hi,

 In this case you need to follow my first suggestion - download all your data on the client and export after everything is downloaded. In this case however you may get communication exception during service serialization (in case of lots of data). 

Regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Nick
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Nick
Top achievements
Rank 1
Share this question
or