Skip to main content
Tab

ASPxGridView.RowInserting Event

Enables you to cancel adding a new row.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v26.1.dll

NuGet Package: DevExpress.Web

Declaration

public event ASPxDataInsertingEventHandler RowInserting

Event Data

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

Property Description
Cancel Gets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
NewValues Gets a dictionary that contains the new field name/value pairs for the row to be inserted.

Remarks

The RowInserting event occurs when a user tries to save the newly inserted row by clicking the Update command. To cancel the insert operation, set the Cancel argument property to true.

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

To create a new row, click the New command or call the AddNewRow() method.

After a new row has been added to ASPxGridView, the RowInserted 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 RowInserting, RowUpdating, and RowDeleting events and update the data source manually.

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

<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>
protected void MasterGridView_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e) {
    ds = (DataSet)Session["DataSet"];
    ASPxGridView gridView = (ASPxGridView)sender;
    DataTable dataTable = gridView.GetMasterRowKeyValue() != null ? ds.Tables[1] : ds.Tables[0];
    DataRow row = dataTable.NewRow();
    e.NewValues["ID"] = GetNewId();
    IDictionaryEnumerator enumerator = e.NewValues.GetEnumerator();
    enumerator.Reset();
    while (enumerator.MoveNext())
        if (enumerator.Key.ToString() != "Count")
            row[enumerator.Key.ToString()] = enumerator.Value;
    gridView.CancelEdit();
    e.Cancel = true;
    dataTable.Rows.Add(row);
}
See Also