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

Export to Excel from RadGrid inside RadWindow

2 Answers 120 Views
Window
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 29 Apr 2015, 08:04 PM

We have several pages where we have successfully exported RadGrid contents to Excel using the ExportToExcel() method.  However, we now have a situation where we have a multi-page wizard using a MultiView controls and one of the View controls has a RadGrid on it with a preview of some results.  The users would like to be able to export this RadGrid to Excel.  However, the typical code does not work:

 

        protected void ExportToExcelButton_Click(object sender, EventArgs e)
        {
            PreviewGrid.ExportSettings.IgnorePaging = true;
            PreviewGrid.ExportSettings.OpenInNewWindow = true;
            PreviewGrid.MasterTableView.ExportToExcel();
        }

The RadGrid is fairly simple:

 

<telerik:RadGrid ID="PreviewGrid" AutoGenerateColumns="False" 
                    OnNeedDataSource="PreviewGrid_NeedDataSource" 
                    runat="server" Width="730px" Height="362px">
    <ClientSettings>
        <Selecting EnableDragToSelectRows="false"/>
        <Scrolling AllowScroll="true" UseStaticHeaders="True"></Scrolling>
    </ClientSettings>
    <MasterTableView DataKeyNames="Key" NoMasterRecordsText="Nothing would be generated." CommandItemDisplay="Top" >
        <CommandItemTemplate>
            <div class="floatRightDiv" style="margin-top: 3px;margin-left: 700px;display:none;">
                <asp:Button ID="ExportToExcelButton" runat="server" CssClass="rgExpXLS" OnClick="ExportToExcelButton_Click" Visible="false"/>
            </div>
        </CommandItemTemplate>  
        <Columns>
            <telerik:GridBoundColumn UniqueName="Field1" DataField="Field1" HeaderText="Field1"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Field2" DataField="Field2" HeaderText="Field2"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Field3" DataField="Field3" HeaderText="Field3"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Field4" DataField="Field4" HeaderText="Field4"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Field5" DataField="Field5" HeaderText="Field5"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn UniqueName="Amount" DataField="Amount" HeaderText="Amount" DataFormatString="{0:N2}" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right"></telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

 

How can we export from a grid in a window?

2 Answers, 1 is accepted

Sort by
0
Accepted
Marin Bratanov
Telerik team
answered on 30 Apr 2015, 08:17 AM

Hello Richard,

There was an issue when exporting a grid within an iframe (or RadWidow) when a RadMenu was also on the page: http://feedback.telerik.com/Project/108/Feedback/Details/118199-fix-radgrid-exporting-inside-an-iframe-radwindow-when-radmenu-is-present-on-the. Could you check if this is your case as well and if so - whether the solution provided in the page above helps? The issue should be resolved in later releases, so I would advise upgrading to the latest (Q1 2015 SP1 at the time of writing) and see if this helps.

Another common reason for such a problem is AJAX - if the grid is configured to perform AJAX requests, you would not be able to receive the exported file because of the way partial rendering works: http://www.telerik.com/help/aspnet-ajax/grid-export-with-ajax-enabled.html.

I just tried the scenario (I only had to make the button available on the page) and things seemed to work fine for me.

Thus, If neither of the above ideas help, I advise opening a ticket and sending us a small, runnable sample that showcases the issue, so we can debug it. 

Regards,

Marin Bratanov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Richard
Top achievements
Rank 1
answered on 30 Apr 2015, 02:15 PM

Turns out the issue was AJAX-related.  We have the standard onRequestStart code to set_enableAjax(false) on the export button in a MasterPageFile named Default.Master, but these RadWindows utilize Dialog pages that use a MasterPageFile of Dialog.Master.  Dialog.Master was missing the onRequestStart code and ClientEvents settings in its RadAjaxManager.  Now the export is being properly output.

Thank you for the reply.

Tags
Window
Asked by
Richard
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Richard
Top achievements
Rank 1
Share this question
or