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

RadGrid - Ajax - Pagination/Sorting - Export Excel

1 Answer 149 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Leandro
Top achievements
Rank 1
Leandro asked on 19 Aug 2013, 09:49 PM
Hi Follows, First Sorry about my english.

I am with the following problem.

I Have a "Radgridview" configured with options for export to excel, pagination, pagesized and sorting and it are inside a "RadAjaxPanel" basically.

follows the structure:
<telerik:RadAjaxPanel ...
<telerik:RadGrid OnItemCommand="GridView_RowCommand" OnPageIndexChanged="GridView_Pagination"
                OnPageSizeChanged="GridView_PageSize"
...

the function "export to excel" needs of real postback to do the exportation, for this I've been used the "RegisterPostBackControl" forcing the button of the exportation to do the postback.

Follows the code:

ScriptManager.GetCurrent(Page).RegisterPostBackControl(exportButton);

I Don't use DataSource plugged on RadGrid, in all interaction like pagination or change page size or sorting, I use method on the code-behind to do the search again and I force the RegisterPostBackControl again.


Basically the methods apply the instructions and do the new search. OBS: Pagination, pagesized, Sorting are Ok.

The Problem:

When I changed the page or sorting or pagesized, and after any this actions I try to export to excel, the all grid rebind but without pagination control, pagesized control and the sorting and the export dont work.



 protected virtual void GridView_RowCommand(object sender, GridCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case SharedHardCode.CommandName.View:
                    this.ViewObject(sender, e);
                    break;
                case SharedHardCode.CommandName.Active:
                    this.ActiveObject(sender, e);
                    break;
                case RadGrid.ExportToExcelCommandName:
                    this.ExportToExcel(((RadGrid)sender));
                    break;
                case SharedHardCode.CommandName.ExportToPdf:
                    this.ExportToPdf(((RadGrid)sender));
                    break;
            }
        }


   protected void GridView_Pagination(object sender, GridPageChangedEventArgs e)
        {
            this.PaginationHelper((RadGrid)sender);
        }

    protected void GridView_Bind(object dataSource, RadGrid grid)
        {
            grid.DataSource = dataSource;
            grid.DataBind();
            grid.Rebind();

            //Registra controles de exportação como postback
            this.RegisterPostBackControl(ExportToExcelButton);
            }





1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 22 Aug 2013, 07:32 AM
Hi Leandro,

Please note that using DataBind() is not recommended. Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, 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
Advanced Data Binding

As for exporting the content of an Ajaxified grid, you can use the approach demonstrated in the following article:
http://www.telerik.com/help/aspnet-ajax/grid-export-with-ajax-enabled.html

Hope this helps.

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Leandro
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or