Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Deleting Row from GridView
Message
 
 
To
26/03/2010 09:23:21
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Environment versions
Environment:
C# 3.0
Miscellaneous
Thread ID:
01457427
Message ID:
01457462
Views:
35
Frank,

I think I solved this exact problem before (though in plain ASP.NET, not in MM.NET). I must have posted some code here, I think, or let me know if you need it and I'll search in a project.

>Hi,
>
>I have a Client Table with a 1 to Many relationship with an Addresses Table. My form to edit this data has the Client data and a GridView with the Addresses. This is an ASP.NET application using MM.NET and C#.
>
>When I delete an address from this grid view I want the address to disappear from the form, but I don't want it actually deleted from the data until the user clicks on the Save button.
>
>Currently my code for the deletion is this:
>
>
        /// <summary>
>        /// Addresses Row Deleting Event Handler
>        /// </summary>
>        protected void grdAddresses_RowDeleting(object sender, GridViewDeleteEventArgs e)
>        {
>            DataSet dsAddress = (DataSet)Session["dsAddress"];
>            this.oAddress.Delete(dsAddress, e.RowIndex);
>            this.BindControl(this.grdAddresses);
>        }
>
>But this removes the address completely from the database, even if the user subsequently presses the Cancel button.
>
>So I tried changing the code to this:
>
>
        protected void grdAddresses_RowDeleting(object sender, GridViewDeleteEventArgs e)
>        {
>            DataSet dsAddress = (DataSet)Session["dsAddress"];
>            dsAddress.Tables[0].Rows[e.RowIndex].Delete();
>            Session["dsAddress"] = dsAddress;
>            this.BindControl(this.grdAddresses);
>        }
>
>This removes the row from the dataset and is reflected properly in the grid. But when I subsequently hit the Save button I get this error:
>
>Deleted row information cannot be accessed through the row.
>Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
>
>Exception Details: System.Data.DeletedRowInaccessibleException: Deleted row information cannot be accessed through the row.
>
>Source Error:
>
>Line 24: {
>Line 25: if (this.Row != null)
>Line 26: return (string)mmType.GetNullableDbValue(this.Row["Address1"]);
>Line 27: else
>Line 28: return this._address1;
>
>
>Source File: C:\Development\Mere Mortals .NET Framework 2008\SamaanSystems\IAS.Business\Address\AddressEntity.cs Line: 26
>
>Stack Trace:
>
>[DeletedRowInaccessibleException: Deleted row information cannot be accessed through the row.]
> System.Data.DataRow.GetDefaultRecord() +4814901
> System.Data.DataRow.get_Item(String columnName) +22
> SamaanSystems.IAS.Business.AddressEntity.get_Address1() in C:\Development\Mere Mortals .NET Framework 2008\SamaanSystems\IAS.Business\Address\AddressEntity.cs:26
> SamaanSystems.IAS.Business.AddressRules.CheckRulesHook(mmBindingList`1 entityList) in C:\Development\Mere Mortals .NET Framework 2008\SamaanSystems\IAS.Business\Address\AddressRules.cs:41
> OakLeaf.MM.Main.Business.mmBusinessRule.CheckRules(mmBindingList`1 entityList) +335
> OakLeaf.MM.Main.Business.mmBusinessObjectGeneric`1.CheckRules(mmBusinessObjectGeneric`1 businessObject, mmBindingList`1 entityList) +437
> OakLeaf.MM.Main.Business.mmBusinessObjectGeneric`1.CheckRules() +71
> OakLeaf.MM.Main.Business.mmBusinessObjectGeneric`1.CheckRules(mmBusinessObjectGeneric`1 businessObject, mmBindingList`1 entityList) +695
> OakLeaf.MM.Main.Business.mmBusinessObjectGeneric`1.CheckRules() +71
> OakLeaf.MM.Main.Business.mmBusinessObjectGeneric`1.CheckRules(mmBusinessObject businessObject, DataSet ds, String tableName) +97
> OakLeaf.MM.Main.Business.mmBusinessObject.SaveDataSet(DataSet ds, String tableName, String databaseKey, IDbDataAdapter dbAdapter) +410
> OakLeaf.MM.Main.Business.mmBusinessObject.SaveDataSet(DataSet ds, String tableName, String databaseKey) +53
> OakLeaf.MM.Main.Business.mmBusinessObject.SaveDataSet(DataSet ds, String tableName) +83
> OakLeaf.MM.Main.Business.mmBusinessObject.SaveDataSet(DataSet ds) +74
> OakLeaf.MM.Main.Web.UI.mmBusinessWebPage.Save(mmBusinessObject bizObj, DataSet ds, String tableName) +128
> SamaanSystems.IAS.Web.AgentEdit.btnSave_Click(Object sender, EventArgs e) in C:\Development\Mere Mortals .NET Framework 2008\SamaanSystems\IAS.Web\AgentEdit.aspx.cs:240
> System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
> System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
> System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
> System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
> System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
> System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
>
>Any ideas how I can accomplish this?
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform