Back to Devexpress

ASPxGridBase.BeforeExport Event

aspnet-devexpress-dot-web-dot-aspxgridbase-e745ca4d.md

latest3.8 KB
Original Source

ASPxGridBase.BeforeExport Event

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

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event ASPxGridBeforeExportEventHandler BeforeExport
vb
Public Event BeforeExport As ASPxGridBeforeExportEventHandler

Event Data

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

PropertyDescription
ExportOptionsSpecifies the export parameters.
ExportTargetGets 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 affect only the exported document’s content and do 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.

aspx
<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>
csharp
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 });
}
vb
Protected Sub grid_BeforeExport(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridBeforeExportEventArgs)
    ' 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() With {
        .Caption = "Notes",
        .VisibleIndex = 0
    })
End Sub

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

See Also

ASPxGridBase Class

ASPxGridBase Members

DevExpress.Web Namespace