I am trying to insert data through a listview control which is kept inside a Update Panel. I have used a SQL datasource for showing the existing items. But for inserting the data, I am using stored procedures and calling them through ADO.net Entity framework. I see a strange behavior that if I used direct insert command to the SQLdatasource, the insertmode is closing after successful insertion of data but the insert mode stays (textboxes visible) when I do the insertion through stored procedure. I have used the listview_iteminserted even to set the editindex to -1 and insertitemposition to none. But still no success. Below is the code...
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:ValidationSummary ID="vsumSaveProject" runat="server" ValidationGroup="vgrpSaveProject" EnableClientScript="true" SkinID="valSummaryError" DisplayMode="BulletList" HeaderText="Please correct the below errors." CssClass="validation-summary-errors" />
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:ImageButton ID="imgbNew" runat="server"
CausesValidation="False"
CommandName="New"
ImageUrl="../images/listviews/add_icon_mono.gif"
ToolTip="Add New"
Width="25"
onclick="imgbNew_Click" />
</td>
</tr>
<tr>
<td>
<asp:ListView ID="lvProjects" runat="server"
DataKeyNames="Project_Code"
DataSourceID="SQLProjectsDS"
onitemcommand="lvProjects_ItemCommand"
oniteminserted="lvProjects_ItemInserted"
onitemcanceling="lvProjects_ItemCanceling"
onitemediting="lvProjects_ItemEditing">
And the SQl DataSource as below..
<asp:SqlDataSource ID="SQLProjectsDS" runat="server"
ConnectionString="<%$ ConnectionString %>"
SelectCommand="SELECT Projects.Project_Code, Projects.Project_Name, Projects.Project_Area, Projects.Project_Status, Projects.Display_Mask,Projects.Site_ID SiteID, Site_Details.Site_Nm FROM Projects INNER JOIN Site_Details ON Projects.Site_ID = Site_Details.Site_ID" />
And the code behind is...
private void InsertItemstoDB(parameters.....)
{
using(entity framework)
{
Do Insertions using stored procedure
}
}
And in the Item Inserted Event
protected void lvProjects_ItemInserted(object sender, ListViewInsertedEventArgs e)
{
this.CancelAddNew();
}
private CancelAddNew()
{
lvProjects.InsertItemPosition = InsertItemPosition.None;
imgbNew.Enabled = true;
lvProjects.EditIndex = -1;
}
Now this is the same code which works if I create the Insert Command and send it to SQLDataSource.InsertCommand. With the Stored Proc Insert, the insert is working fine but the insert Mode stays in the display as if nothing happened. On refreshing the page the new data appears.
Please help.