Back to Devexpress

ASPxGridView.RowUpdating Event

aspnet-devexpress-dot-web-dot-aspxgridview-665c146e.md

latest7.2 KB
Original Source

ASPxGridView.RowUpdating Event

Enables you to prevent a row from being updated.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event ASPxDataUpdatingEventHandler RowUpdating
vb
Public Event RowUpdating As ASPxDataUpdatingEventHandler

Event Data

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

PropertyDescription
CancelGets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
KeysGets a dictionary of field name/value pairs that represent the primary key of the row to update.
NewValuesGets a dictionary that contains the values of the non-key field name/value pairs in the row to be updated.
OldValuesGets a dictionary that contains the original field name/value pairs in the row to be updated.

Remarks

The RowUpdating event occurs when a user has changed cell values and tries to pass them to the data source by clicking the Update command. To cancel the update operation, set the Cancel argument property to true.

If you use edit form templates, you should process the update manually in the RowUpdating event handler.

After a row has been updated, the RowUpdated event is raised.

Example

This example demonstrates how to use ASPxGridView to edit an in-memory data set with a master-detail relationship.

View Example: How to edit an in-memory data set with a master-detail relationship

To enable this behavior, follow the steps below:

  1. Handle the RowUpdating, RowInserting, and RowDeleting events and update the data source manually.

  2. Set the cancel argument property to true and call the grid’s CancelEdit() method.

aspx
<dx:ASPxGridView ID="MasterGridView" runat="server" AutoGenerateColumns="False" SettingsPager-PageSize="3"
    KeyFieldName="ID" OnRowUpdating="MasterGridView_RowUpdating" Width="588px" OnRowDeleting="MasterGridView_RowDeleting" OnRowInserting="MasterGridView_RowInserting">
    <!-- ... -->
    <SettingsDetail ShowDetailRow="True" />
    <Templates>
        <DetailRow>
            <dx:ASPxGridView ID="DetailGridView" runat="server" AutoGenerateColumns="False" SettingsPager-PageSize="4"
                KeyFieldName="ID" OnBeforePerformDataSelect="DetailGridView_BeforePerformDataSelect"
                OnRowUpdating="MasterGridView_RowUpdating" Width="100%">
                <!-- ... -->
            </dx:ASPxGridView>
        </DetailRow>
    </Templates>
</dx:ASPxGridView>
csharp
protected void MasterGridView_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) {
    ds = (DataSet)Session["DataSet"];
    ASPxGridView gridView = (ASPxGridView)sender;
    DataTable dataTable = gridView.GetMasterRowKeyValue() != null ? ds.Tables[1] : ds.Tables[0];
    DataRow row = dataTable.Rows.Find(e.Keys[0]);
    IDictionaryEnumerator enumerator = e.NewValues.GetEnumerator();
    enumerator.Reset();
    while (enumerator.MoveNext())
        row[enumerator.Key.ToString()] = enumerator.Value;
    gridView.CancelEdit();
    e.Cancel = true;
}
vb
Protected Sub MasterGridView_RowUpdating(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxDataUpdatingEventArgs)
    ds = CType(Session("DataSet"), DataSet)
    Dim gridView As ASPxGridView = CType(sender, ASPxGridView)
    Dim dataTable As DataTable = If(gridView.GetMasterRowKeyValue() IsNot Nothing, ds.Tables(1), ds.Tables(0))
    Dim row As DataRow = dataTable.Rows.Find(e.Keys(0))
    Dim enumerator As IDictionaryEnumerator = e.NewValues.GetEnumerator()
    enumerator.Reset()
    While enumerator.MoveNext()
        row(enumerator.Key.ToString()) = enumerator.Value
    End While

    gridView.CancelEdit()
    e.Cancel = True
End Sub

Online Examples

View Example: Implement the Select All check box for a templated column in batch edit mode

View Example: How to use the Rich Text Editor to edit formatted text in the Edit Form

View Example: How to upload files and save them to a binary column in edit mode

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the RowUpdating event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

asp-net-web-forms-grid-create-master-detail-grid-at-runtime/CS/MasterDetailGrids/Default.aspx.cs#L38

csharp
masterGrid.Templates.DetailRow = new DetailGridTemplate();
    masterGrid.RowUpdating += new DevExpress.Web.Data.ASPxDataUpdatingEventHandler(masterGrid_RowUpdating);
}

asp-net-web-forms-grid-create-master-detail-grid-at-runtime/VB/MasterDetailGrids/Default.aspx.vb#L40

vb
masterGrid.Templates.DetailRow = New DetailGridTemplate()
    AddHandler masterGrid.RowUpdating, AddressOf masterGrid_RowUpdating
End Sub

See Also

ASPxGridView Class

ASPxGridView Members

DevExpress.Web Namespace