you need to do some minor changes in your FormView Defination
as
put two buttons in ItemTemplate of FormView as
Edit:
<asp:Button ID="Edit" runat="server" Text="Edit" CommandName="edit" />
<br />
New:
<asp:Button ID="new" runat="server" Text="New" CommandName="new" />
<br />
;
and put a code in ItemCommand Event Handler of your FormView..
as
protected void Envelope_ItemCommand(object sender, FormViewCommandEventArgs e)
{
if (e.CommandName.ToLower() == "new")
Envelope.DefaultMode = FormViewMode.Insert;
else if (e.CommandName.ToLower() == "cancel")
Envelope.DefaultMode = FormViewMode.ReadOnly;
}
Now if you want to Insert or Update from CodeBehind, means you want manually write the Command and Connection objects code then do that in
FormView_Updated Event Handler and FormView_Inserted Event Handler
or you can also do that from you SqlDataSource by setting the Insert,Update and Delete Command of SqlDataSource
Hope you will get some help from this..