How to switch to edit mode in FormView?

I have a FormView:

<asp:FormView ID="fvReport" runat="server" DefaultMode="ReadOnly" AllowPaging="false" OnModeChanging="fvReport_ModeChanging" DataKeyNames="id"> protected void fvReport_ModeChanging(Object sender, FormViewModeEventArgs e) { switch (e.NewMode) { case FormViewMode.Edit: fvReport.AllowPaging = false; break; } } 

in ItemTamplate I installed LinkButton:

 <asp:LinkButton ID="lbEdit" runat="server" CausesValidation="true" CommandName="Edit" CommandArgument='<%# Eval("id") %>'></asp:LinkButton> 

Of course, FormView has an EditItemTemplate section.

When I click the button, the FormView updates and stays in ReadOnly. What am I doing wrong?

+8
c # formview
source share
2 answers

you need to call the ChangeMode FormView method and pass the mode

 fvReport.ChangeMode(DetailsViewMode.Edit); 
+13
source share

Another option that I usually use to go into edit mode from a form is to add and define an EditItemTemplate element. This makes editing your application much easier.

In your View form, you may need to change the DefaultMode to "Change." Also in your code for trying:

 protected void fvReport_ModeChanging(Object sender, FormViewModeEventArgs e) { } protected void lbEdit_Click(object sender, EventArgs e) { LinkButton lbEdit = (LinkButton)fvReport.FindControl("lbEdit"); if (sender == lbEdit) { fvReport.DataBind(); fvReport.ChangeMode(FormViewMode.Edit); } } 
0
source share

All Articles