aspnet-devexpress-dot-web-dot-aspxgridbase-e745ca4d.md
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
public event ASPxGridBeforeExportEventHandler BeforeExport
Public Event BeforeExport As ASPxGridBeforeExportEventHandler
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. |
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.
<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 });
}
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