Reputation: 265
When i click to remove a item all items are removed from cartObjects. I am not understanding they are all removed and not only the one with the matching id. Please guide me through this problem.
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandArgument.ToString().ToLower() == "remove")
{
GetCartId(Convert.ToInt32(e.CommandName));
}
}
private void GetCartId(int CartId)
{
cartObjects.RemoveAll(i => i.Id == CartId);
Repeater1.DataBind();
}
protected void btnRemove_Click(object sender, EventArgs e)
{
GetCartId(CartId);
}
I am importing my data through webapi.
Thanks and regards.
Upvotes: 0
Views: 1818
Reputation: 86
try
cartObjects.Where(x => x.Id != CartId).ToList();
You should be able to filter all items having Id equal to "CartId" with above.
Upvotes: 2