Skip to main content

Export Vertical Grid Data

  • 2 minutes to read

The ASPxVerticalGrid control allows you to export data to a file or stream in PDF, RTF, CSV, XLS, XLSX, and DOCX formats. To allow users to export data in your application, you can either rely on the grid’s built-in UI or use the client and server APIs in code.

Run Demo: Vertical Grid - Exporting to Different Formats

VerticalGrid_Export

The export commands and the client API are disabled for security reasons (the default setting). To enable this functionality, set the EnableClientSideExportAPI property to true.

Important

DevExpress controls require the DevExpress.RichEdit.v23.2.Export.dll library to export their content to DOCX or RTF format.

Toolbar Commands

The ASPxVerticalGrid toolbar implements the following commands to export grid data: ExportToCsv, ExportToPdf, ExportToRtf, ExportToDocx, ExportToXls, and ExportToXlsx.

Populate a grid toolbar with a VerticalGridToolbarItem object and set its Command property to an export command to add the corresponding item to the toolbar.

Run Demo: Toolbar Read Tutorial: ASPxVerticalGrid toolbars

<dx:ASPxVerticalGrid ID="VerticalGrid" runat="server" KeyFieldName="ProductID" DataSourceID="ProductsDataSource" Width="100%">
    <Toolbars>
    <dx:VerticalGridToolbar EnableAdaptivity="true">
            <Items>
                <dx:VerticalGridToolbarItem Command="ExportToXls" />
                <dx:VerticalGridToolbarItem Command="ExportToXlsx" />
                <dx:VerticalGridToolbarItem Command="ExportToCsv" />
            </Items>
        </dx:VerticalGridToolbar>
    </Toolbars>
    <!-- ... -->
</dx:ASPxVerticalGrid>

Client API

Call the client ExportTo(format) method to export grid data to a file in the specified format.

<dx:ASPxVerticalGrid ClientInstanceName="verticalGrid" ID="ASPxVerticalGrid1" runat="server" Width="700px" AutoGenerateRows="False" DataSourceID="SqlDataSource3" KeyFieldName="ProductID">
    <SettingsExport EnableClientSideExportAPI="true" />
    <Rows>
    ...
    </Rows>
</dx:ASPxVerticalGrid>
<br />
<dx:ASPxButton ID="ASPxButton1" runat="server" AutoPostBack="False" Text="Export">
    <ClientSideEvents Click="function(s, e) {
        verticalGrid.ExportTo(ASPxClientVerticalGridExportFormat.Xls);
    }" />
</dx:ASPxButton>

Server API

The ASPxVerticalGrid component implements the following export methods:

Format Export to a Stream Export to the Response
CSV ExportToCsv ExportCsvToResponse
DOCX ExportToDocx ExportDocxToResponse
PDF ExportToPdf ExportPdfToResponse
RTF ExportToRtf ExportRtfToResponse
XLS ExportToXls ExportXlsToResponse
XLSX ExportToXlsx ExportXlsxToResponse
switch(e.Item.Name) {
    case "CustomExportToXLS":
        verticalGrid.ExportXlsToResponse(new DevExpress.XtraPrinting.XlsExportOptionsEx { ExportType = ExportType.WYSIWYG });
        break;
    case "CustomExportToXLSX":
        verticalGrid.ExportXlsxToResponse(new DevExpress.XtraPrinting.XlsxExportOptionsEx { ExportType = ExportType.WYSIWYG });
        break;
    default:
        break;
}

You can use the StylesExport property to customize the exported ASPxVerticalGrid elements’ appearance.

Limitations

  • The ASPxVerticalGrid control supports WYSIWYG (What You See Is What You Get) export mode only.
  • Hidden data records are not exported.
  • Templates’ content is not exported. Templated elements are exported with their default representation. For instance, if you export a grid with templated cells, they are represented as default labels with text in the exported file.