Skip to main content
A newer version of this page is available. .
Tab

ASPxGridBase.BeforeExport Event

Occurs before the grid content is exported and allows you to customize export settings.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v22.1.dll

NuGet Package: DevExpress.Web

Declaration

public event ASPxGridBeforeExportEventHandler BeforeExport

Event Data

The BeforeExport event's data class is ASPxGridBeforeExportEventArgs. The following properties provide information specific to this event:

Property Description
ExportOptions Specifies the export parameters.
ExportTarget Gets the export format.

Remarks

Use the BeforeExport event to customize export settings before grid content is exported.

When you export ASPxGridView‘s content, the control generates a corresponding document and write this document into the server’s response. It means that any settings you change in the BeforeExport event handler are only affect the exported document’s content and are not affect the current ASPxGridView configuration.

Run Demo: ASPxGridView - Export Data

The code sample below demonstrates how to hide and add columns in an exported document.

<dx:ASPxGridView ID="grid" runat="server" DataSourceID="CustomerReportsDataSource" 
    AutoGenerateColumns="False" OnBeforeExport="grid_BeforeExport">
    <Columns>
        <dx:GridViewDataColumn Caption="Product Name" FieldName="ProductName" />
        <dx:GridViewDataColumn Caption="Company Name" FieldName="CompanyName" />
        <dx:GridViewDataColumn Caption="Order Date" FieldName="OrderDate" Visible="false"/>
        <dx:GridViewDataTextColumn Caption="Product Amount" FieldName="ProductAmount" ReadOnly="True">
            <PropertiesTextEdit DisplayFormatString="c" />
        </dx:GridViewDataTextColumn>
    </Columns>
    <%--...--%>
</dx:ASPxGridView>
protected void grid_BeforeExport(object sender, DevExpress.Web.ASPxGridBeforeExportEventArgs e) {
    // Hides the ProductName column.
    grid.Columns["ProductName"].Visible = false;
    // Shows the hidden OrderDate column.
    grid.Columns["OrderDate"].Visible = true;
    // Adds a new Notes column.
    grid.Columns.Add(new DevExpress.Web.GridViewDataColumn() { Caption = "Notes", VisibleIndex = 0 });
}

See the following topic for more examples: Grid Export: Task-Based Examples

See Also