protected void MyGridView_RowEditing(object sender, GridViewEditEventArgs e) { MyGridView.EditIndex = e.NewEditIndex; } protected void MyGridView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { MyGridView.EditIndex = -1; e.Cancel = true; }
protected void MyGridView_RowEditing(object sender, GridViewEditEventArgs e) { MyGridView.EditIndex = e.NewEditIndex; } protected void MyGridView_RowUpdating(object sender, GridViewUpdateEventArgs e) { // Custom validation code if (e.NewValues["MyField"] == null) { e.Cancel = true; } }In this example, when the user clicks the Update button to save their changes, the `RowUpdating` event handler is fired. This event handler performs custom validation by checking the value of the "MyField" field in the `NewValues` property of the `GridViewUpdateEventArgs`. If the value is null, the editing operation is canceled by setting the `Cancel` property of the `GridViewUpdateEventArgs` object to true. Overall, the System.Web.UI.WebControls GridViewCancelEditEventArgs class is a useful tool for handling user editing operations in a GridView control in ASP.NET.