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

2. Export to functionality (PDF|Excel|etc) is not working

2 Answers 153 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ankit
Top achievements
Rank 1
Ankit asked on 08 Aug 2011, 03:35 PM

Nothing happens when we click on any of the export to excel or export to CSV , ... buttons.

The code snippet of the grid we are using is as below :-

 

<telerik:RadGrid AutoGenerateColumns="false" ID="grdxyz" runat="server"  AllowPaging="True" AllowSorting="True" OnNeedDataSource="grdSearchResults_NeedDataSource" TabIndex="36" >
<ExportSettings HideStructureColumns="False" ExportOnlyData="False" IgnorePaging="false" OpenInNewWindow="true" FileName="MyRecord">
</ExportSettings>
<MasterTableView PageSize="10"  TableLayout="Auto" Width="100%"  CommandItemDisplay="Top" DataKeyNames="myid">
<CommandItemSettings ShowAddNewRecordButton="false" ShowRefreshButton="true" ShowExportToPdfButton="true" ShowExportToCsvButton="true" ShowExportToExcelButton="true" ShowExportToWordButton="true" />

Our page hierarchy is as follows. We have a master page which has a contentTemplate. On the child page we have a RadAjaxPanel and the above RadGrid is placed inside this RadAjaxPanel on child page. Has the ajaxification of the grid anything to do with these ??

Also we are using the latest version of telerik i.e v.2011.2.712.40.

Let me know accordingly.

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Aug 2011, 04:41 AM
Hello Ankit,

The exporting feature of the control work with regular postbacks only. Check the following help documentation which explains more about exporting a ajaxified grid.
Export from Ajaxified Grid.

Thanks,
Princy.
0
Ankit
Top achievements
Rank 1
answered on 22 Aug 2011, 10:47 AM
Thanks for the quick reply..

After going through the article Export from Ajaxified Grid, we have removed the ajaxification affect of the button “Export to excel” and registered it as a complete postback control.

This has been implemented by doing the following changes in .aspx page,

The grid is inside RadAjaxPanel which calls a function onstart :-

<telerik:RadAjaxPanel runat="server" ClientEvents-OnRequestStart="onRequestStart">
  
The Onrequest start method is as follows
<telerik:RadCodeBlock ID="codeblock1" runat="server">
    <script type="text/javascript">
        function onRequestStart(sender, args) {
            //alert('request started');
            if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0) {
               // alert('disbaling ajax as button is found');
                args.set_enableAjax(false);
            }
        }
    </script>
</telerik:RadCodeBlock>

This works fine and gives an empty Excel when the grid has ‘No Results Found’

 

However it gives an exception when the grid has some data in it.

 

The error is Object reference not set to an instance of an object

And the stack trace is:

[NullReferenceException: Object reference not set to an instance of an object.]
   Telerik.Web.UI.GridTableView.PrepareExport() +72
   Telerik.Web.UI.Grid.Export.TableViewExporter.PrepareForExportInternal(GridTableView tableView, Boolean ignorePaging, Boolean dataOnly) +403
   Telerik.Web.UI.GridTableView.ClearTableViewControls(Control control, TableViewExporter exporter, GridTableView ownerTable) +606
   Telerik.Web.UI.Grid.Export.TableViewExporter.PrepareForExportInternal(GridTableView tableView, Boolean ignorePaging, Boolean dataOnly) +703
   Telerik.Web.UI.Grid.Export.TableViewExporter.PrepareForExport() +59
   Telerik.Web.UI.Grid.Export.TableViewExporter.page_PreRender(Object sender, EventArgs e) +34
   System.EventHandler.Invoke(Object sender, EventArgs e) +0
   System.Web.UI.Control.OnPreRender(EventArgs e) +145
   System.Web.UI.Control.PreRenderRecursiveInternal() +209
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4834
Kindly let me know accordingly.

Tags
Grid
Asked by
Ankit
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ankit
Top achievements
Rank 1
Share this question
or