How can I do an update in Linq
My code is
List<Cart> objNewCartItems = (List<Cart>)Session["CartItems"];
if ((objNewCartItems != null) && (objNewCartItems.Count > 0))
{
for (int i = 0; i < dgShoppingCart.Rows.Count; i++)
{
Cart c = new Cart();
TextBox t = (TextBox)dgShoppingCart.Rows[i].FindControl("txtQuantity");
c.Quantity = (t.Text == string.Empty? (int?)null: Convert.ToInt32(t.Text));
objNewCartItems[i].Quantity = c.Quantity;
}
}
Session["CartItems"] = objNewCartItems;
Response.Redirect("ItemListing.aspx", false);
Basically in the Cart Collection, there is an item called an Quantity which will be populated when the user will fill that.
So I am reading the Grid item and updating the Quantity attribute.
But I am sure that there must be a better way via linq or lambda to do the same.
Please help
Thanks in advance