Skip to main content
A newer version of this page is available. .
Tab

ASPxGridView.HtmlDataCellPrepared Event

Enables you to change individual cell settings.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v21.2.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 data cell in the ASPxGridView when the corresponding table cell has been created. You can handle this event to change the style settings of individual cells.

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.

Note

The grid raises this event for visible rows only. For example, the event is raised for rows displayed in a currently selected page when you page data.

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