[英]How to remove items from a shopping cart
When i click to remove a item all items are removed from cartObjects . 当我单击以删除项目时,所有项目都从cartObjects中删除。 I am not understanding they are all removed and not only the one with the matching id.
我不明白它们是否全部被删除,而不仅仅是具有匹配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. 我正在通过webapi导入数据。
Thanks and regards. 谢谢并恭祝安康。
try 尝试
cartObjects.Where(x => x.Id != CartId).ToList();
You should be able to filter all items having Id equal to "CartId" with above. 您应该能够过滤上面所有具有等于“ CartId”的ID的项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.