Problem with Shopping cart

Oct 5, 2011 at 11:16 PM

I am using the code given in the tutorial, the shopping cart page has multiple products selected and when I update the 'Quantity' and 'Remove' and click the 'update shopping cart' button, I am getting correct result only for the 1st row of data, from the 2nd row of data , It is not getting the updated values but it is getting old values before I made the updates to the row. I tried debugging and it appears it is getting the new values correctly only for 1st rows but it gets old values for remaining rows. I am not understanding where I made the mistake , can someone help with it?

Below is the code

  protected void UpdateBtn_Click(object sender, ImageClickEventArgs e) 
MyShoppingCart usersShoppingCart = new MyShoppingCart(); 
String cartId = usersShoppingCart.GetShoppingCartId(); 
ShoppingCartUpdates[] cartUpdates = new ShoppingCartUpdates[MyList.Rows.Count]; 
for (int i = 0; i < MyList.Rows.Count; i++) 
IOrderedDictionary rowValues = new OrderedDictionary(); 
= GetValues(MyList.Rows[i]);                  cartUpdates[i].ProductId = Convert.ToInt32(rowValues["ProductID"]); 
[i].PurchaseQuantity = Convert.ToInt32(rowValues["Quantity"]); 
CheckBox cbRemove = new CheckBox(); 
= (CheckBox)MyList.Rows[i].FindControl("Remove"); 
[i].RemoveItem = cbRemove.Checked; 
.UpdateShoppingCartDatabase(cartId, cartUpdates); 
.Text = String.Format("{0:c}", usersShoppingCart.GetTotal(cartId)); 

Which calls the below method
        public static IOrderedDictionary GetValues(GridViewRow row) 
            IOrderedDictionary values = new OrderedDictionary(); 
            foreach (DataControlFieldCell cell in row.Cells) 
                if (cell.Visible) 
                    //Extract values from the cell 
                    cell.ContainingField.ExtractValuesFromCell(values, cell, row.RowState, true); 
            return values; 


Oct 6, 2011 at 1:11 AM

Hello Steven,

try downloading the source code and compare your written code to that in the downloaded source.  That should be helpfull


Oct 6, 2011 at 3:38 AM

Hello basba,

Thanks , after comparing I found that I was missing a closing bracket after the below line of code, It works fine now.

cartUpdates[i].RemoveItem = cbRemove.Checked;