Built-in Export

  • 4 minutes to read

Note

The information in this topic applies to DevExpress ASP.NET Grid View v17.2 and higher.

The following ASPxGridView tools allow you to export data: toolbar commands, context menu items, and client-side and server-side API.

Note

The built-in toolbar/context menu export commands and client-side API are disabled for security reasons (the default setting). To enable this functionality, set the ASPxGridExportSettings.EnableClientSideExportAPI property to true.

Toolbar Commands

The ASPxGridView toolbar includes the following export commands:

Use the GridViewToolbarItem.Command property to specify a toolbar item’s export command.

Refer to the Toolbars topic or Toolbar online demo for more information on grid toolbars.

<dx:ASPxGridView ID="Grid" runat="server" KeyFieldName="ProductID" DataSourceID="ProductsDataSource" Width="100%">
    <Toolbars>
    <dx:GridViewToolbar EnableAdaptivity="true">
            <Items>
                <dx:GridViewToolbarItem Command="ExportToXls" />
                <dx:GridViewToolbarItem Command="ExportToXlsx" />
                <dx:GridViewToolbarItem Command="ExportToCsv" />
            </Items>
        </dx:GridViewToolbar>
    </Toolbars>
    <Columns>
    ...
    </Columns>
</dx:ASPxGridView>

ASPxGridView-Toolbar-Exporting

Context Menu Items

ASPxGridView’s context menu has an Export submenu that contains the following items:

Item Item’s Visibility Member Command Name
Export to PDF GridViewExportMenuItemVisibility.ExportToPdf GridViewContextMenuCommand.ExportToPdf
Export to RTF GridViewExportMenuItemVisibility.ExportToRtf GridViewContextMenuCommand.ExportToRtf
Export to DOCX GridViewExportMenuItemVisibility.ExportToDocx GridViewContextMenuCommand.ExportToDocx
Export to CSV GridViewExportMenuItemVisibility.ExportToCsv GridViewContextMenuCommand.ExportToCsv
Export to XLS GridViewExportMenuItemVisibility.ExportToXls GridViewContextMenuCommand.ExportToXls
Export to XLSX GridViewExportMenuItemVisibility.ExportToXlsx GridViewContextMenuCommand.ExportToXlsx

Set the GridViewExportMenuItemVisibility.Visible property to true to display the Export submenu.

Refer to the Context Menu topic or Context Menu online demo for more information on the grid’s context menu.

ASPxGridView-Export-ContextMenu

Export API

Execute a client or server export method to implement grid data export. See the following topic for details: Member Table: Built-in Export.

The following code samples illustrate how to use client and server export methods:

  • Client API

    <dx:ASPxGridView ClientInstanceName="grid" ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" KeyFieldName="ProductID">
    <SettingsExport EnableClientSideExportAPI="true" />
            <Columns>
            ...
            </Columns>
    </dx:ASPxGridView>
    <br />
    <dx:ASPxButton ID="ASPxButton1" runat="server" AutoPostBack="False" Text="Export">
        <ClientSideEvents Click="function(s, e) {
            grid.ExportTo(ASPxClientGridViewExportFormat.Xls);
        }" />
    </dx:ASPxButton>
    
  • Server API

    switch(e.Item.Name) {
        case "CustomExportToXLS":
            grid.ExportXlsToResponse(new DevExpress.XtraPrinting.XlsExportOptionsEx { ExportType = ExportType.WYSIWYG });
            break;
        case "CustomExportToXLSX":
            grid.ExportXlsxToResponse(new DevExpress.XtraPrinting.XlsxExportOptionsEx { ExportType = ExportType.WYSIWYG });
            break;
        default:
            break;
    }
    

The ASPxGridViewDetailSettings object has the following export settings:

Property

Description

AllowOnlyOneMasterRowExpanded

Specifies whether you can expand multiple master rows simultaneously.

ExportIndex

Specifies the detail view’s position among other views in a printed document.

ExportMode

Specifies which detail rows users can export.

ShowDetailButtons

Specifies whether the grid displays detail buttons.

ShowDetailRow

Specifies whether the grid displays detail rows.

You can customize exported grid element appearance with the ASPxGridView.StylesExport property.

Note

The ASPxGridView cannot export data columns that are hidden or export template content. If the grid is in a GridViewTemplates.DetailRow template, ASPxGridView allows you to export both master and detail data.

Note that templated elements are exported with their default display views. For instance, if you export a grid with templated cells, they are displayed as default labels with text in the exported file.

Excel Data Aware Export

When you export data in XLS and XLSX formats, the following grid data is maintained in the resulting Excel document.

  • Data grouping with the ability to collapse/expand groups within a worksheet.
  • Data sorting and filtering.
  • Totals and group summaries with the ability to modify/change formulas.
  • Format conditions with the ability to modify/change conditional formatting rules.
  • Data validation for combo-box columns.
  • Fixed columns.

See the following Knowledge Base Article for more information: ASPxGridView / MVC GridView Extension - Excel Data Aware Export FAQ.

Note

The grid ignores custom text specified in the CustomColumnDisplayText event handler when it exports content to XLSX and XLS formats. To include custom cell text in an exported document, handle the ExportRenderBrick event.

Export Limitations

Data-Aware Mode Limitations

Use the WYSIWYG (What You See Is What You Get) export mode to avoid the specified limitations. Note, however, that table formatting is lost in this mode.

ASPxGridView1.ExportXlsxToResponse(new XlsxExportOptionsEx { ExportType = ExportType.WYSIWYG });

Online Demos

Exporting to Different Formats

Excel Data Aware Export

Export Selected Records

Export Master-Detail Records

Export with Format Conditions

Export with Data Cell Bands

Context Menu

Member Table

Task-Based Help