i making small ebook store project. storing cart in asp session list of objects. now, in checkout page, showing list of objects in list box , allowing user delete item if needed. code
protected void btncart_click(object sender, eventargs e) { list<title> cartitems = (list<title>)session["estorecart"]; int itemtoremove = int32.parse(lbcartitems.selecteditem.value); title ttl = ebs.titles.singleordefault(t => t.titleid == itemtoremove); cartitems.remove(ttl); session["estorecart"] = cartitems; filllistbox(); } apparently, number of items in cartitems same before , after remove() method called. going wrong? similar method used in add card cartitems.add(ttl), working flawlessly.
instead of
title ttl = ebs.titles.singleordefault(t => t.titleid == itemtoremove); try
title ttl = cartitems.singleordefault(t => t.titleid == itemtoremove); i.e. instead of searching title in 'ebs' (not sure contains, not clear in op code), search items in session object directly , remove it.
Comments
Post a Comment