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

ExportToExcel does not returns anything/does not work

1 Answer 301 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Miguel
Top achievements
Rank 1
Miguel asked on 19 Apr 2017, 09:59 PM

While I read many posts about this issue, none seem to fit my particular problem.

I have a very simple web form, with a grid, which is not ajaxified, in server side code, I call a complex object that returns a simple list of items as a datatable and set it as datasource for my grid. The grids works and displays all OK, however when I try to export to xlsx (and actually any supported format), nothing happens after calling MasterTableView.ExportToExcel().

I did verified that the grdWarranties items is not empty and that the datasource is not lost. Below substract of the web page and the server side code to execute the export:

Protected Sub btnExport_Click(sender As Object, e As Telerik.Web.UI.ImageButtonClickEventArgs) Handles btnExport.Click
 
        grdWarranties.Page.Response.ClearHeaders()
        grdWarranties.Page.Response.Cache.SetCacheability(HttpCacheability.Private)
 
        grdWarranties.ExportSettings.Excel.Format = Telerik.Web.UI.GridExcelExportFormat.Xlsx
        grdWarranties.ExportSettings.IgnorePaging = False
        grdWarranties.ExportSettings.ExportOnlyData = True
        grdWarranties.ExportSettings.OpenInNewWindow = True
        grdWarranties.MasterTableView.ExportToExcel()
 
    End Sub

 

<asp:Panel runat="server">
               <table  class="WarrantyCheckTable" style="margin-top:15px">
                   <tr>
                       <td style="width:15%">
                           <telerik:RadLabel ID="RadLabel1" Text="Type or paste in your Landis+Gyr serial numbers:" runat="server" Font-Size="Small" Font-Italic="True"></telerik:RadLabel>
                           <telerik:RadTextBox ID="txtMSNs" runat="server" TextMode="MultiLine" BorderColor="#7AB800" BorderWidth="1px" Height="93%" Width="100%" Wrap="False" ></telerik:RadTextBox>
                       </td>
                       <td style="width:5%">
                           <telerik:RadImageButton ID="btnGo" runat="server" Text="Go!" Skin="Telerik"></telerik:RadImageButton>
                       </td>
                       <td >                           
                           <telerik:RadGrid ID="grdWarranties" runat="server" AllowSorting="True" AutoGenerateColumns="False" ShowGroupPanel="True" Width="100%" ViewStateMode="Enabled" RenderMode="Lightweight" >
                               <GroupingSettings CollapseAllTooltip="Collapse all groups" />
                               <ExportSettings ExportOnlyData="True" FileName="WarrantyData" OpenInNewWindow="True">
                                   <Excel FileExtension="xlsx" Format="Xlsx" />
                                   <Csv EncloseDataWithQuotes="False" />
                               </ExportSettings>
                               <ClientSettings AllowDragToGroup="True">
                                   <Scrolling AllowScroll="True" ScrollHeight="600px" UseStaticHeaders="True" />
                               </ClientSettings>
                               <MasterTableView>
                                   <Columns>
                                       <telerik:GridBoundColumn DataField="MSN" FilterControlAltText="Filter colMSN column" HeaderText="MSN" UniqueName="colMSN">
                                           <FooterStyle HorizontalAlign="Center" />
                                           <ItemStyle HorizontalAlign="Left" />
                                       </telerik:GridBoundColumn>
                                       <telerik:GridBoundColumn DataField="CSN" FilterControlAltText="Filter colCSN column" HeaderText="CSN" UniqueName="colCSN">
                                           <FooterStyle HorizontalAlign="Center" />
                                           <ItemStyle HorizontalAlign="Left" />
                                       </telerik:GridBoundColumn>
                                       <telerik:GridBoundColumn DataField="METERTYPE" FilterControlAltText="Filter colType column" HeaderText="Type" UniqueName="colType">
                                           <FooterStyle HorizontalAlign="Center" />
                                           <ItemStyle HorizontalAlign="Left" />
                                       </telerik:GridBoundColumn>
                                       <telerik:GridBoundColumn DataField="CATALOG" FilterControlAltText="Filter colCatalog column" HeaderText="Catalog" UniqueName="colCatalog">
                                           <FooterStyle HorizontalAlign="Center" />
                                           <ItemStyle HorizontalAlign="Left" />
                                       </telerik:GridBoundColumn>
                                       <telerik:GridBoundColumn DataField="SOLDDATE" FilterControlAltText="Filter colSoldDate column" HeaderText="Ship Date" UniqueName="colSoldDate" DataFormatString="{0:MMM dd, yyyy}" DataType="System.DateTime">
                                           <FooterStyle HorizontalAlign="Center" />
                                           <ItemStyle HorizontalAlign="Left" />
                                       </telerik:GridBoundColumn>
                                       <telerik:GridBoundColumn DataField="WARRANTY" FilterControlAltText="Filter colWarranty column" HeaderText="Warranty Status" UniqueName="colWarranty">
                                           <FooterStyle HorizontalAlign="Center" />
                                           <ItemStyle HorizontalAlign="Left" />
                                       </telerik:GridBoundColumn>
                                   </Columns>
                               </MasterTableView>
                               <FilterMenu RenderMode="Lightweight">
                               </FilterMenu>
                               <HeaderContextMenu RenderMode="Lightweight">
                               </HeaderContextMenu>
                           </telerik:RadGrid>
                            
                       </td>
                   </tr>
               </table>
           </asp:Panel>

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 24 Apr 2017, 06:25 AM
Hi Miguel,

Please make sure that you are not using the DataBind() method to bind the grid. Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Exporting, 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 (DataSourceID property)
Programmatic Data Binding (NeedDataSource event, + DetailTableDataBind for hierarchy). You should set the DataSource property ONLY within these event handlers.


In addition, I am also sending a sample RadGrid web site which you can use as a base reference.

Regards,
Eyup
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Miguel
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or