Back to Devexpress

ASPxGridView.RowInserted Event

aspnet-devexpress-dot-web-dot-aspxgridview-0c4ffc50.md

latest5.1 KB
Original Source

ASPxGridView.RowInserted Event

Fires after a new row has been added to the ASPxGridView.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event ASPxDataInsertedEventHandler RowInserted
vb
Public Event RowInserted As ASPxDataInsertedEventHandler

Event Data

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

PropertyDescription
AffectedRecordsGets the number of records affected by the update operation. Inherited from ASPxDataBaseUpdatedEventArgs.
ExceptionGets the exception (if any) that was raised during the update operation. Inherited from ASPxDataBaseUpdatedEventArgs.
ExceptionHandledGets or sets whether an exception raised during the update operation was handled in the event handler. Inherited from ASPxDataBaseUpdatedEventArgs.
NewValuesGets a dictionary that contains the values of the non-key field name/value pairs in the row to be inserted.

Remarks

Users can create new rows by clicking the New command. To create rows in code, use the ASPxGridView.AddNewRow method. To save the newly created row, users must click the Update command.

To cancel the insert operation, handle the ASPxGridView.RowInserting event.

Note

The RowInserted event fires even though an exception occurs during the data update operation. Use the ASPxDataBaseUpdatedEventArgs.Exception and ASPxDataBaseUpdatedEventArgs.ExceptionHandled argument properties to determine whether or not any exception occurs during the corresponding action, and handle it if you wish.

Example

The following example demonstrates how to handle the grid’s RowInserted event to focus the newly inserted row:

View Example: How to focus the newly inserted row

After the grid adds a new row to the data source, you can get the row’s key value in the grid’s server-side RowInserted event. To focus the newly inserted row, call the grid’s FindVisibleIndexByKeyValue(Object) method to get the row’s visible index and assign that index to the grid’s FocusedRowIndex property:

csharp
protected void grid_RowInserted (object sender, ASPxDataInsertedEventArgs e) {
    object newKey = null;
    if (e.AffectedRecords == 1) {
        ICollection objects = uof.GetObjectsToSave();
        if (objects != null && objects.Count == 1) {
            IEnumerator enumeration = objects.GetEnumerator();
            enumeration.MoveNext();
            Customer obj = (Customer)enumeration.Current;
            uof.CommitChanges();
            newKey = obj.Oid;
        }
    }
    grid.FocusedRowIndex = grid.FindVisibleIndexByKeyValue(newKey);
}
vb
Protected Sub grid_RowInserted(ByVal sender As Object, ByVal e As ASPxDataInsertedEventArgs)
    Dim newKey As Object = Nothing

    If e.AffectedRecords = 1 Then
        Dim objects As ICollection = uof.GetObjectsToSave()

        If objects IsNot Nothing AndAlso objects.Count = 1 Then
            Dim enumeration As IEnumerator = objects.GetEnumerator()
            enumeration.MoveNext()
            Dim obj As Customer = CType(enumeration.Current, Customer)
            uof.CommitChanges()
            newKey = obj.Oid
        End If
    End If

    grid.FocusedRowIndex = grid.FindVisibleIndexByKeyValue(newKey)
End Sub

See Also

RowInserting

Grid View

ASPxGridView Class

ASPxGridView Members

DevExpress.Web Namespace