Back to Devexpress

ASPxGridView.ExportRenderBrick Event

aspnet-devexpress-dot-web-dot-aspxgridview-49442860.md

latest6.0 KB
Original Source

ASPxGridView.ExportRenderBrick Event

Allows you to customize an exported grid element.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event ASPxGridViewExportRenderingEventHandler ExportRenderBrick
vb
Public Event ExportRenderBrick As ASPxGridViewExportRenderingEventHandler

Event Data

The ExportRenderBrick 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

Handle the ExportRenderBrick event to customize an exported grid element, for instance, color grid cells or export images contained in a column of the GridViewDataImageColumn type.

aspx
<dx:ASPxGridView ID="grid" runat="server" AutoGenerateColumns="False" DataSourceID="XmlDataSource1" 
    OnExportRenderBrick="grid_ExportRenderBrick">
    <Columns>
        <dx:GridViewDataTextColumn FieldName="Common_Name" Caption="Common name" />
        <dx:GridViewDataTextColumn FieldName="Species_Name" Caption="Species name" />
        <dx:GridViewDataImageColumn FieldName="ImagePath" Caption="Image">
            <PropertiesImage>
                <ExportImageSettings Width="180" Height="120" />
            </PropertiesImage>
        </dx:GridViewDataImageColumn>
    </Columns>
    <%--...--%>
</dx:ASPxGridView>
csharp
byte[] GetImageBinaryData(string relativePath) {
    string path = Server.MapPath(relativePath);
    return File.Exists(path) ? File.ReadAllBytes(path) : null;
}

protected void grid_ExportRenderBrick(object sender, ASPxGridViewExportRenderingEventArgs e) {
    var dataColumn = e.Column as GridViewDataColumn;
    if (dataColumn != null && dataColumn.FieldName == "ImagePath" && e.RowType == GridViewRowType.Data)
        e.ImageValue = GetImageBinaryData(e.Value.ToString());
}
vb
Private Function GetImageBinaryData(ByVal relativePath As String) As Byte()
    Dim path As String = Server.MapPath(relativePath)
    Return If(File.Exists(path), File.ReadAllBytes(path), Nothing)
End Function

Protected Sub grid_ExportRenderBrick(ByVal sender As Object, ByVal e As ASPxGridViewExportRenderingEventArgs)
    Dim dataColumn = TryCast(e.Column, GridViewDataColumn)
    If dataColumn IsNot Nothing AndAlso dataColumn.FieldName = "ImagePath" AndAlso e.RowType = GridViewRowType.Data Then e.ImageValue = GetImageBinaryData(e.Value.ToString())
End Sub

View Example: How to export images from the column of the GridViewDataImageColumn typeView Example: How to export a colored grid in WYSIWYG export mode

Limitation

The ExportRenderBrick event does not fire in DataAware export mode. Use the XlsExportOptionsEx.CustomizeCell or XlsxExportOptionsEx.CustomizeCell event instead.

See Also

Grid View

ASPxGridView Class

ASPxGridView Members

DevExpress.Web Namespace