I want to add a empty row in my Grid.
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton id="Insert" runat="server" CausesValidation="false"
CommandName="Insert" OnClick="GridViewInsert"
ImageUrl="~/Images/Grid/Insert.gif" />
In GridViewInsert Event:
Award_Status_List list = new Award_Status_List();
list.Award_Status_Code = " ";
list.Award_Status_Desc = " ";
list.Is_Active = false;
list.Job_User = " ";
list.Job_Name = " ";
list.Job_Date = DateTime.Now;
_entity.AddToAward_Status_List(list);
_entity.SaveChanges();
GridView2.DataBind();
In save changes I get this error:
System.Data.OptimisticConcurrencyException was unhandled by user code Message="Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries." Source="System.Data.Entity" StackTrace: at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter) at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache) at System.Data.Objects.ObjectContext.SaveChanges(Boolean acceptChangesDuringSave) at System.Data.Objects.ObjectContext.SaveChanges() at Default1.GridViewInsert(Object sender, EventArgs e) in c:\Documents and Settings\mranganathan\My Documents\Visual Studio 2008\WebSites\Accounting\Default1.aspx.cs:line 68 at System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) at System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)