How to go to Edit Mode in FormView?

DmitryB picture DmitryB · Apr 20, 2011 · Viewed 18.5k times · Source

I have 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 put LinkButton:

<asp:LinkButton ID="lbEdit" runat="server" CausesValidation="true" CommandName="Edit" CommandArgument='<%# Eval("id") %>'>Редактировать</asp:LinkButton>

Of course, FormView has EditItemTemplate section.

When I click Button, FormView is refreshed and stays in ReadOnly. What am I doing wrong?

Answer

Muhammad Akhtar picture Muhammad Akhtar · Apr 20, 2011

you have to call ChangeMode method of FormView and pass the mode

fvReport.ChangeMode(DetailsViewMode.Edit);