Undo editing the Gridview while updating the ObjectDataSource event

In my Asp.net webpage, I have a GridView control bound to an ObjectDataSource. The user can edit the row directly in the GridView. There are times when an update fails validation. When this happens, I would like to update the line that will remain in edit mode.

In the onUpdating event handler, the event args object has a cancel property. But I need to check if an update has occurred in the onUpdated handler, and it does not have the e.Cancel property.

Therefore, I need to know how to make the GridView row remain in edit mode if the update does not work.

+4
source share
3 answers

Very simple, you can save the editing mode e.KeepInEditMode = true;

 protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e) { e.KeepInEditMode = true; } 
+4
source

One way to solve this problem is to use Validation controls that will restrict the user from sending a request if validation fails.

But in order to keep gridview in update mode, you must save its edit index property, because when gridview is not in edit mode, usually its edit index is -ve, but if it is in edit mode, the gridview edit index is set to some positive integer value.

You can also link to this link: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewupdatedeventargs.keepineditmode.aspx

0
source

save the value of EditIndex in a variable. Cancel the gridview bu update GridView1.EditIndex=-1; and then, to save the Gridview in edit mode, you can set the EditIndex value again with the index value previously saved.

0
source

All Articles