Friday, May 15, 2009

ASP.NET FormView won’t stay in Edit mode after an update (by default)

The ASP.NET FormView has default behavior such that after you make it update, it changes the mode to ReadOnly. I want to change this behavior so that it stays in edit mode after an update command has been issued.

I don’t consider it very intuitive, but I did find the answer. All you have to  is use the ItemUpdated of the FormView.

protected void formview1_ItemUpdated(object sender, FormViewUpdatedEventArgs e)
{
e.KeepInEditMode = true;
}
Likewise, there is the same scenario for Insert.
protected void formview1_ItemInserted(object sender, FormViewInsertedEventArgs e)
{
e.KeepInInsertMode = true;
}

No comments: