Back to Devexpress

ASPxGridView.HtmlRowPrepared Event

aspnet-devexpress-dot-web-dot-aspxgridview-387555eb.md

latest4.5 KB
Original Source

ASPxGridView.HtmlRowPrepared Event

Enables the settings of individual rows to be changed.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event ASPxGridViewTableRowEventHandler HtmlRowPrepared
vb
Public Event HtmlRowPrepared As ASPxGridViewTableRowEventHandler

Event Data

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

PropertyDescription
KeyValueGets an object that uniquely identifies the row.
RowGets the processed row.
RowTypeGets the processed row’s type.
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 HtmlRowPrepared event is raised for each grid row (data row, group row, etc.) within the ASPxGridView. You can handle this event to change the style settings of individual rows.

Note

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

The HtmlRowPrepared and ASPxGridView.HtmlRowCreated events are not fired for the grid’s column header row and title row. So, the ASPxGridViewTableRowEventArgs.RowType property is never set to GridViewRowType.Title or GridViewRowType.Header within these event arguments.

GitHub Examples

Example

In this example, the HtmlRowPrepared event is handled to highlight the products whose price is less than $20 or more than $50.

csharp
protected void ASPxGridView1_HtmlRowPrepared(object sender, DevExpress.Web.ASPxGridViewTableRowEventArgs e) {
        if (e.RowType != GridViewRowType.Data) return;
        int price = Convert.ToInt32(e.GetValue("UnitPrice"));
        if (price < 20)
            e.Row.BackColor = System.Drawing.Color.LightCyan; 
        if (price > 50)
            e.Row.ForeColor = System.Drawing.Color.DarkRed;
    }
vb
Protected Sub ASPxGridView1_HtmlRowPrepared(sender As Object, e As DevExpress.Web.ASPxGridViewTableRowEventArgs)
    If e.RowType <> GridViewRowType.Data Then
        Return
    End If
    Dim price As Integer = Convert.ToInt32(e.GetValue("UnitPrice"))
    If price < 20 Then
        e.Row.BackColor = System.Drawing.Color.LightCyan
    End If
    If price > 50 Then
        e.Row.ForeColor = System.Drawing.Color.DarkRed
    End If
End Sub

See Also

HtmlRowCreated

HtmlDataCellPrepared

Grid View

ASPxGridView Class

ASPxGridView Members

DevExpress.Web Namespace