Skip to main content
Tab

ASPxGridView.HtmlDataCellPrepared Event

Enables you to change individual cell settings.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v24.1.dll

NuGet Package: DevExpress.Web

Declaration

public event ASPxGridViewTableDataCellEventHandler HtmlDataCellPrepared

Event Data

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

Property Description
Cell Gets the processed data cell.
CellValue Gets the processed cell’s value.
DataColumn Gets the data column that contains the processed cell.
KeyValue Gets an object that uniquely identifies the data row. Inherited from ASPxGridViewItemEventArgs.
VisibleIndex Gets the visible index of the data row. Inherited from ASPxGridViewItemEventArgs.

The event data class exposes the following methods:

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

Remarks

The grid raises the HtmlDataCellPrepared event for each visible data cell in the ASPxGridView when the corresponding table cell has been created. For example, the event is raised for rows displayed in a currently selected page when you page data. You can handle this event to change the style settings of individual cells.

Note

During export operations, the Grid View control ignores appearance settings specified in the HtmlDataCellPrepared event handler. Refer to the following topic for more information on how to customize exported elements in different export modes: Export Modes.

The processed cell is identified by the event parameter’s ASPxGridViewTableDataCellEventArgs.Cell property. Its value is returned by the ASPxGridViewTableDataCellEventArgs.CellValue property. The column and row where the processed cell resides can be obtained via the ASPxGridViewTableDataCellEventArgs.DataColumn and ASPxGridViewItemEventArgs.KeyValue properties.

To get values of other cells within the processed row, use the e.GetValue method.

View Example: How to export a colored grid in Data Aware export mode

Online Example

View Example: How to show a popup with an enlarged image on mouse hover

Example

This example handles the ASPxGridView.HtmlDataCellPrepared event to highlight the Budget column’s cells whose values are less than 100,000.

<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" KeyFieldName="ID"
    OnHtmlDataCellPrepared="ASPxGridView1_HtmlDataCellPrepared">
    <Columns>
        <dx:GridViewDataTextColumn FieldName="DepartmentName" Caption="Department" />
        <dx:GridViewDataSpinEditColumn FieldName="Budget">
            <PropertiesSpinEdit DisplayFormatString="c0" />
        </dx:GridViewDataSpinEditColumn>
        <dx:GridViewDataTextColumn FieldName="Location" />
        <dx:GridViewDataTextColumn FieldName="Phone1" Caption="Phone" />
    </Columns>
</dx:ASPxGridView>
protected void ASPxGridView1_HtmlDataCellPrepared(object sender,
    DevExpress.Web.ASPxGridViewTableDataCellEventArgs e) {
    if(e.DataColumn.FieldName != "Budget")
        return;
    if(Convert.ToInt32(e.CellValue) < 100000)
        e.Cell.BackColor = System.Drawing.Color.LightCyan;
}

The image below shows the result:

HtmlDataCellPrepared

See Also