Back to Devexpress

ASPxGridViewExporter.RenderBrick Event

aspnet-devexpress-dot-web-dot-aspxgridviewexporter-37891f29.md

latest5.9 KB
Original Source

ASPxGridViewExporter.RenderBrick Event

Enables rendering of different content from the default export.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event ASPxGridViewExportRenderingEventHandler RenderBrick
vb
Public Event RenderBrick As ASPxGridViewExportRenderingEventHandler

Event Data

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

PropertyDescription
BrickStyleGets the style settings used to paint report bricks.
ColumnGets a data column that corresponds to the processed grid element.
ImageValueGets or sets an array of bytes that contains the processed brick’s image.
KeyValueGets the processed row’s key.
RowTypeGets the processed row’s type.
TextGets or sets the text displayed within the brick currently being rendered.
TextValueGets or sets the processed brick’s value.
UrlGets or sets the rendered brick’s URL.
ValueGets the processed data cell’s value.
VisibleIndexGets the processed row’s visible index.
XlsExportNativeFormatSpecifies the format settings that are applied to a document when it is exported to XLS format.
XlsxFormatStringSpecifies the format string applied to the processed brick’s value when exporting to Excel format (XLS or XLSX).

The event data class exposes the following methods:

MethodDescription
GetValue(String)Returns the value of the specified cell within the processed row.

Remarks

The event parameter’s Column property returns a null reference if the grouped column is currently being processed. In this instance, the Text property specifies the text displayed within the processed group row. You can assign a new value to this property, to provide custom text within an exported document.

Note

The RenderBrick event does not fire when export data in DataAware mode. The DataAware mode is enabled by default when you export the grid to an XLS, XLSX or CSV file. In this case, you can disable the DataAware mode by setting the ASPxGridViewExportSettings.ExcelExportMode to ExportType.WYSIWYG or use the XlsExportOptionsEx.CustomizeCell or XlsxExportOptionsEx.CustomizeCell event instead the RenderBrick.

Example

This example shows how to draw company names in an exported document based on the number of products. Company names are painted in Green if the product count is greater than 1,000. Otherwise, company names are painted in Red.

The image below shows the result:

csharp
using DevExpress.Web.Export;
using DevExpress.Web.ASPxGridView;

protected void grid_ExportRenderBrick(object sender, DevExpress.Web.ASPxGridViewExportRenderingEventArgs e) {
    GridViewDataColumn dataColumn = e.Column as GridViewDataColumn;
    if(e.RowType == GridViewRowType.Data && dataColumn != null && dataColumn.FieldName == "CompanyName") {
        e.BrickStyle.ForeColor = (decimal)e.GetValue("ProductAmount") > 1000 ? Color.Green : Color.Red;
        e.BrickStyle.BackColor = Color.LightYellow;
    }
}

protected void btn_Click(object sender, EventArgs e) {
    grid.ExportPdfToResponse();
}
vb
Imports DevExpress.Web.Export
Imports DevExpress.Web.ASPxGridView

Protected Sub grid_ExportRenderBrick(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridViewExportRenderingEventArgs)
    Dim dataColumn As GridViewDataColumn = TryCast(e.Column, GridViewDataColumn)
    If e.RowType = GridViewRowType.Data AndAlso dataColumn IsNot Nothing AndAlso dataColumn.FieldName = "CompanyName" Then
        e.BrickStyle.ForeColor = If(CDec(e.GetValue("ProductAmount")) > 1000, Color.Green, Color.Red)
        e.BrickStyle.BackColor = Color.LightYellow
    End If
End Sub

Protected Sub btn_Click(ByVal sender As Object, ByVal e As EventArgs)
    grid.ExportPdfToResponse()
End Sub

See Also

Export Grid View Data

ASPxGridViewExporter Class

ASPxGridViewExporter Members

DevExpress.Web Namespace