Example E4756
Visible to All Users

Grid View for ASP.NET Web Forms - How to export images from the column of the GridViewDataImageColumn type

The ASPxGridView control exports images contained in a column of the GridViewDataBinaryImageColumn type.

If your grid displays images in a column of the GridViewDataImageColumn type, handle the ExportRenderBrick event and assign the image to the ImageValue property.

C#
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()); }

Note that the ExportRenderBrick event does not fire in DataAware export mode, so you should set the export mode to WYSIWIG.

C#
protected void btnXlsExport_Click(object sender, EventArgs e) { Grid.ExportXlsToResponse(new XlsExportOptionsEx() { ExportType = ExportType.WYSIWYG }); } protected void btnXlsxExport_Click(object sender, EventArgs e) { Grid.ExportXlsxToResponse(new XlsxExportOptionsEx() { ExportType = ExportType.WYSIWYG }); }

Files to Review

Documentation

Technical Demos

Example Code

Export/Default.aspx
ASPx
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.master" CodeBehind="Default.aspx.cs" Inherits="Export._Default" %> <asp:Content ID="Content" ContentPlaceHolderID="MainContent" runat="server"> <table> <tr> <td style="padding-right: 4px"> <dx:ASPxButton ID="btnPdfExport" runat="server" Text="Export to PDF" OnClick="btnPdfExport_Click" /> </td> <td style="padding-right: 4px"> <dx:ASPxButton ID="btnXlsExport" runat="server" Text="Export to XLS" OnClick="btnXlsExport_Click" /> </td> <td style="padding-right: 4px"> <dx:ASPxButton ID="btnXlsxExport" runat="server" Text="Export to XLSX" OnClick="btnXlsxExport_Click" /> </td> <td style="padding-right: 4px"> <dx:ASPxButton ID="btnRtfExport" runat="server" Text="Export to RTF" OnClick="btnRtfExport_Click" /> </td> </tr> </table> <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> <SettingsPager PageSize="5" /> </dx:ASPxGridView> <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/Fishes.xml" /> </asp:Content>
Export/Default.aspx.cs
C#
using System; using System.IO; using DevExpress.Export; using DevExpress.Web; using DevExpress.XtraPrinting; namespace Export { public partial class _Default : System.Web.UI.Page { 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()); } protected void btnPdfExport_Click(object sender, EventArgs e) { Grid.ExportPdfToResponse(); } protected void btnXlsExport_Click(object sender, EventArgs e) { Grid.ExportXlsToResponse(new XlsExportOptionsEx() { ExportType = ExportType.WYSIWYG }); } protected void btnXlsxExport_Click(object sender, EventArgs e) { Grid.ExportXlsxToResponse(new XlsxExportOptionsEx() { ExportType = ExportType.WYSIWYG }); } protected void btnRtfExport_Click(object sender, EventArgs e) { Grid.ExportRtfToResponse(); } byte[] GetImageBinaryData(string relativePath) { string path = Server.MapPath(relativePath); return File.Exists(path) ? File.ReadAllBytes(path) : null; } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.