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

Export to Excel

6 Answers 136 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Abdul
Top achievements
Rank 2
Abdul asked on 26 Nov 2010, 04:20 PM
Please Tell me simple way to export my grid contents to Excel...
I am using DataTable to bind data with grid

6 Answers, 1 is accepted

Sort by
0
Accepted
Marin
Telerik team
answered on 26 Nov 2010, 06:26 PM
Hello Abdul,

The grid supports automatic export to Excel/Word/PDF. You can show the built-in export buttons from the CommandItemSettings for the grid by setting ShowExportToExcelButton="true". Please have a look at the following demo showing the various exports functionalies for the grid and how they are configured.

Greetings,
Marin
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Abdul
Top achievements
Rank 2
answered on 29 Nov 2010, 08:40 AM
by setting this property to true it just refresh the grid on click does not give an option to download the excel file, i have manually called the ExportToExcel method but still not working

<telerik:RadGrid ID="grd_report" runat="server"  AllowPaging="True"
            OnNeedDataSource="grd_report_NeedDataSource" AllowAutomaticDeletes="True"
            Skin="Web20" AllowSorting="True" GridLines="None"  OnItemCommand="grd_report_ItemCommand">
            <MasterTableView Width="100%" CommandItemDisplay="Top">
            <PagerStyle Mode="NextPrevNumericAndAdvanced" />
            <CommandItemSettings ShowExportToExcelButton="true" ShowAddNewRecordButton = "false"/>
            </MasterTableView>
         </telerik:RadGrid>
 
 
        protected void grd_report_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToExcelCommandName)
            {
                grd_report.MasterTableView.ExportToExcel();
            }
        }
0
Abdul
Top achievements
Rank 2
answered on 29 Nov 2010, 08:50 AM
Is there any relation in the download option and telerik header I have used the normal html header 
0
Abdul
Top achievements
Rank 2
answered on 29 Nov 2010, 08:50 AM
do i need to add javascript for exporting grid contents to excel even on export to excel button enables ?
0
Abdul
Top achievements
Rank 2
answered on 29 Nov 2010, 10:30 AM
<script type="text/javascript">
        function onRequestStart(sender, args)
        {
            if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 ||
                    args.get_eventTarget().indexOf("ExportToWordButton") >= 0 ||
                    args.get_eventTarget().indexOf("ExportToCsvButton") >= 0)
            {
                args.set_enableAjax(false);
            }
        }
    </script>

This block of code is must... please change it according to your need
0
Marin
Telerik team
answered on 29 Nov 2010, 01:47 PM
Hello Abdul,

To clarify: The exporting feature works only with regular postbacks. This means that if you have ajaxified grid, you should temporary disable the asynchronous postback to allow the save window to pop up. You can get more information in this help article: Export from ajaxified grid. One possible option is to wire the OnRequestStart event for the AjaxManager with the following code as you already found:

function onRequestStart(sender, args)
        {
            if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0)
            {
                args.set_enableAjax(false);
            }
        }


Best wishes,

Marin
the Telerik team

 

Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Abdul
Top achievements
Rank 2
Answers by
Marin
Telerik team
Abdul
Top achievements
Rank 2
Share this question
or