Back to Devexpress

ASPxGridView.HtmlDataCellPrepared Event

aspnet-devexpress-dot-web-dot-aspxgridview-57552eaa.md

latest5.7 KB
Original Source

ASPxGridView.HtmlDataCellPrepared Event

Enables you to change individual cell settings.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event ASPxGridViewTableDataCellEventHandler HtmlDataCellPrepared
vb
Public Event HtmlDataCellPrepared As ASPxGridViewTableDataCellEventHandler

Event Data

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

PropertyDescription
CellGets the processed data cell.
CellValueGets the processed cell’s value.
DataColumnGets the data column that contains the processed cell.
KeyValueGets an object that uniquely identifies the data row. Inherited from ASPxGridViewItemEventArgs.
VisibleIndexGets the visible index of the data row. Inherited from ASPxGridViewItemEventArgs.

The event data class exposes the following methods:

MethodDescription
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.

aspx
<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>
csharp
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;
}
vb
Protected Sub ASPxGridView1_HtmlDataCellPrepared(ByVal sender As Object,_
    ByVal e As DevExpress.Web.ASPxGridViewTableDataCellEventArgs)_
    Handles ASPxGridView1.HtmlDataCellPrepared
    If e.DataColumn.FieldName = "Budget" Then
        If Convert.ToInt32(e.CellValue) < 100000 Then
            e.Cell.BackColor = System.Drawing.Color.LightCyan
        End If
    End If
End Sub

The image below shows the result:

See Also

Grid View

ASPxGridView Class

ASPxGridView Members

DevExpress.Web Namespace