ASPxGridView.RowInserting Event
Enables you to cancel adding a new row.
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v24.2.dll
Declaration
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
.
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.
To enable this behavior, follow the steps below:
Handle the
RowInserting
, RowUpdating, and RowDeleting events and update the data source manually.Set the
cancel
argument property totrue
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);
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the RowInserting 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.