I have a shopping cart ListView control backed by a custom object that has methods for selecting and deleting. In the ListView, one of the columns is an ImageButton that is essentially a delete icon, with the CommandName parameter set to CommandName="Delete".
My issue is related to updating the shopping cart ListView on delete; as the delete method is stored in the custom business entity object, I am having trouble in terms of updating the calculations made inside the cart (we have deleted an item, so I need to recalc shipping, taxes, etc).
Right now, I have the cart ListView control calling it’s calculate method in page load on Not Page.IsPostBack, but obviously this isn’t triggered by the delete method.
Any recommendations on where to handle calling the calculate method on deletion when deletion is happening outside of the scope of the control in my custom business logic?
Consider binding your recalculation method to your
ListView‘s ItemDeleted Event. For instance:Honestly, the error checking for
AffectedRowsmight be a bit extraneous for your use case, but it never hurts to know what information is available to you in theListViewDeletedEventArgs.EDIT:
If you need to add support to your business logic for information regarding the number of rows affected by the transaction, ensure first that the method called by the
ObjectDataSource.DeleteMethodproperty has a return value that is either an integer or has a property or function that will return one. Next, add a handler to your ObjectDataSource.Deleted event. Here, you can assign the return value from the method that is contained in the event arguments to another event argument member similarly calledAffectedRows. For instance:Since
e.ReturnValueis passed in as anObject, you can cast it as needed and access any particular property that has the information required to updatee.AffectedRows.The value provided to these arguments will be passed on to your
ListView.ItemDeletedevent.