protected void UpdateCart_Click(object sender, EventArgs e)
{
int rowsCount = Gv1.Rows.Count;
GridViewRow gridRow;
TextBox quantityTextBox;
int productId;
int quantity;
bool success = true;
for (int i = 0; i < rowsCount; i++)
{
// Get a row
gridRow = Gv1.Rows[i];
// The ID of the product being deleted
productId =Convert.ToInt32(Gv1.DataKeys[i].Value.ToString());
// Get the quantity TextBox in the Row
quantityTextBox = (TextBox)gridRow.FindControl("editQuantity");
// Get the quantity, guarding against bogus values
if (Int32.TryParse(quantityTextBox.Text, out quantity))
{
Dictionary<int, int> cartItems = (Dictionary<int, int>)Session["ShoppingCart"];
int Sqty;
if (cartItems.TryGetValue(productId, out Sqty))
{
// cartItems.Remove(abcid);
//Sqty = Sqty + qty;
cartItems[productId] = (quantity);
}
Session["ShoppingCart"] = cartItems;
}
else
{
// if TryParse didn't succeed
success = false;
}
// Display status message
statusLabel.Text = success ?
"<br />Your shopping cart was successfully updated!<br />" :
"<br />Some quantity updates failed! Please verify your cart!<br />";
}
// Repopulate the control
// PopulateControls();
dataload();
}