Back to Devexpress

ASPxGridView.HtmlRowCreated Event

aspnet-devexpress-dot-web-dot-aspxgridview-b16fc872.md

latest4.7 KB
Original Source

ASPxGridView.HtmlRowCreated Event

Occurs when a table row has been created.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event ASPxGridViewTableRowEventHandler HtmlRowCreated
vb
Public Event HtmlRowCreated As ASPxGridViewTableRowEventHandler

Event Data

The HtmlRowCreated 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 HtmlRowCreated event is raised for each grid row (data row, group row, etc.) within the ASPxGridView when the corresponding table row has been created. You can handle this event to initialize web controls contained within the grid templates.

The HtmlRowCreated and ASPxGridView.HtmlRowPrepared 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.

Example

In this example, the ASPxGridView.HtmlRowCreated event is handled to dynamically change the images displayed within the Change column’s cells. These images are contained within the Change column’s GridViewDataColumn.DataItemTemplate and indicate how symbol values are changed on a market.

The image below shows the result:

csharp
using System.Web.UI.WebControls;
...
protected void grid_HtmlRowCreated(object sender, 
DevExpress.Web.ASPxGridViewTableRowEventArgs e) {
    if(e.RowType != DevExpress.Web.GridViewRowType.Data) return;
    Label label = grid.FindRowCellTemplateControl(e.VisibleIndex, null, "changePercent") as Label;
    decimal change = (decimal)e.GetValue("Change");
    label.Text = string.Format("{0:p}", change);
    Image img = grid.FindRowCellTemplateControl(e.VisibleIndex, null, "changeImage") as Image;
    img.Visible = false;
    if(change != 0) {
        img.Visible = true;
        img.ImageUrl = change < 0 ? "~/Images/arRed.gif" : "~/Images/arGreen.gif";
    }
}
vb
Imports System.Web.UI.WebControls
...
Protected Sub grid_HtmlRowCreated(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridViewTableRowEventArgs)
    If e.RowType <> DevExpress.Web.GridViewRowType.Data Then Return
    Dim label As Label = TryCast(grid.FindRowCellTemplateControl(e.VisibleIndex, Nothing, "changePercent"), Label)
    Dim change As Decimal = CDec(e.GetValue("Change"))
    label.Text = String.Format("{0:p}", change)
    Dim img As Image = TryCast(grid.FindRowCellTemplateControl(e.VisibleIndex, Nothing, "changeImage"), Image)
    img.Visible = False

    If change <> 0 Then
        img.Visible = True
        img.ImageUrl = If(change < 0, "~/Images/arRed.gif", "~/Images/arGreen.gif")
    End If
End Sub

See Also

HtmlRowPrepared

Grid View

ASPxGridView Class

ASPxGridView Members

DevExpress.Web Namespace