aspnet-devexpress-dot-web-dot-aspxgridview-d9bf1558.md
Enables you to cancel adding a new row.
Namespace : DevExpress.Web
Assembly : DevExpress.Web.v25.2.dll
NuGet Package : DevExpress.Web
public event ASPxDataInsertingEventHandler RowInserting
Public Event RowInserting As ASPxDataInsertingEventHandler
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. |
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.
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:
Handle the RowInserting, RowUpdating, and RowDeleting events and update the data source manually.
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);
}
Protected Sub MasterGridView_RowInserting(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxDataInsertingEventArgs)
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.NewRow()
e.NewValues("ID") = GetNewId()
Dim enumerator As IDictionaryEnumerator = e.NewValues.GetEnumerator()
enumerator.Reset()
While enumerator.MoveNext()
If Not Equals(enumerator.Key.ToString(), "Count") Then row(enumerator.Key.ToString()) = enumerator.Value
End While
gridView.CancelEdit()
e.Cancel = True
dataTable.Rows.Add(row)
End Sub
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.
detailGrid.DataBind();
detailGrid.RowInserting += new DevExpress.Web.Data.ASPxDataInsertingEventHandler(detailGrid_RowInserting);
detailGrid.RowUpdating += new DevExpress.Web.Data.ASPxDataUpdatingEventHandler(detailGrid_RowUpdating);
detailGrid.DataBind()
AddHandler detailGrid.RowInserting, AddressOf detailGrid_RowInserting
AddHandler detailGrid.RowUpdating, AddressOf detailGrid_RowUpdating
See Also