arvee2003
asked on
FormView: Insert Record Issues
Hi,
I have a formview for insert and updates. I was trying to call a procedure in formview_itemcommand event without setting InsertMethod for the ObjectDataSource. I got an
error and so I gave the exact procedure name for insert method to get rid of the error.
Since the formview objectdatasource method does not exactly match (the no of argument and name) with FormView Datasource(in insertiemtemplate), I was trying to avoid calling the selectmethod defined.
I was able to insert the record in itemcommand event.
The problem is
1. While exiting out the Item_command event it gives the following error
Microsoft JScript runtime error: Sys.WebForms.PageRequestMa nagerServe rErrorExce ption: FormView 'FormViewInsertApplication '
must be in insert mode to insert a new record.
2. After insert, I tried setting the default mode readonly. It does not work
How do I by pass the above problems or is there other better way of accomplishing the same.
Thanks
Suresh
Sections of Code
----------------------
protected void FormViewInsertApplication_ ItemComman d(object sender, FormViewCommandEventArgs e)
{
FormView fvApp = (FormView)FindControl("For mViewInser tApplicati on");
if (e.CommandName == "Insert")
{
if (!doValidate()) { return; }
// Call Insert Procedure
//Check return status . If return > 0 set the formview to readonly
dataMaint psMaint = new dataMaint();
newID = psMaint.InsertApp(paramete r list) // This works
if (Convert.ToInt32(newID) > 0)
{
fvApp.ChangeMode(FormViewM ode.ReadOn ly);
return; // error after this
}
}
<asp:FormView ID="FormViewInsertApplicat ion" runat="server"
DefaultMode="Insert" DataKeyName="id"
DataSourceID="ObjectDataSo urce1"
OnItemCommand="FormViewIns ertApplica tion_ItemC ommand"
OnItemCreated="FormViewIns ertApplica tion_ItemC reated">
</asp:FormView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetApplicati onListByID "
InsertMethod="InsertApp"
TypeName="dataMaint">
<SelectParameters>
<asp:SessionParameter Name="id" SessionField="sid"
Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
I have a formview for insert and updates. I was trying to call a procedure in formview_itemcommand event without setting InsertMethod for the ObjectDataSource. I got an
error and so I gave the exact procedure name for insert method to get rid of the error.
Since the formview objectdatasource method does not exactly match (the no of argument and name) with FormView Datasource(in insertiemtemplate), I was trying to avoid calling the selectmethod defined.
I was able to insert the record in itemcommand event.
The problem is
1. While exiting out the Item_command event it gives the following error
Microsoft JScript runtime error: Sys.WebForms.PageRequestMa
must be in insert mode to insert a new record.
2. After insert, I tried setting the default mode readonly. It does not work
How do I by pass the above problems or is there other better way of accomplishing the same.
Thanks
Suresh
Sections of Code
----------------------
protected void FormViewInsertApplication_
{
FormView fvApp = (FormView)FindControl("For
if (e.CommandName == "Insert")
{
if (!doValidate()) { return; }
// Call Insert Procedure
//Check return status . If return > 0 set the formview to readonly
dataMaint psMaint = new dataMaint();
newID = psMaint.InsertApp(paramete
if (Convert.ToInt32(newID) > 0)
{
fvApp.ChangeMode(FormViewM
return; // error after this
}
}
<asp:FormView ID="FormViewInsertApplicat
DefaultMode="Insert" DataKeyName="id"
DataSourceID="ObjectDataSo
OnItemCommand="FormViewIns
OnItemCreated="FormViewIns
</asp:FormView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetApplicati
InsertMethod="InsertApp"
TypeName="dataMaint">
<SelectParameters>
<asp:SessionParameter Name="id" SessionField="sid"
Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER