Reputation: 307
List<ShoppingCartView> removeitem = (List<ShoppingCartView>)Session["ShoppingView"];
I want to remove a row on clicking that particular product. For example if I click on product xxx and want to remove the product xxx from Session["ShoppingView"], the rest of the list should remain the same.
Upvotes: 2
Views: 2746
Reputation: 8451
You can use Remove
Session["ShoppingView"] = (List<ShoppingCartView>)Session["ShoppingView"].Remove((List<ShoppingCartView>)Session["ShoppingView"].Where(x => x.id== sessionItemToRemove).ToList());
Upvotes: 2
Reputation: 51
You can do it like this
List<string> foo = Session["ShoppingView"];
foo.Remove("xxx");
Session["ShoppingView"] = foo;
Upvotes: 0
Reputation: 63065
you have to edit the condition accordingly
var list = (List<ShoppingCartView>)Session["ShoppingView"];
Session["ShoppingView"] = list.Where(x => x.ProductName!= "pname").ToList();
Upvotes: 2