Change Mode Of DetailsView FormView From Default Mode Insert

Change Mode Of DetailsView FormView From Default Mode set to Insert If you have a DetailsView or FormView on your aspx page and set it's Default mode to Insert than after record insertion it's mode can be changed to default mode by writing following code in ItemInserted Event

protected void DetailsView1_ItemInserted
(object sender, DetailsViewInsertedEventArgs e)
{
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
}


But this code doesn't work , reason being DefaultMode is applied after the call to change the mode , to get it working or to get the mode changed, u need to write code like this
protected void DetailsView1_ItemInserted
(object sender, DetailsViewInsertedEventArgs e)
{
e.KeepInInsertMode = true;
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);

}


Now mode will be changed , similarly you can change the mode to edit.

If you like this post than join us or share

Find More Articles