title: C# - Can't update quantity in grid view
body: <p>I am trying to update the quantity of a product in grid view and it doesn't update.
  For example, Product A has 1 quantity currently in the shopping cart and I want to edit it to increase the quantity (e.g. 3), however after clicking update, the quantity remains 1.</p>
  
  <p>Can somebody explain to me what I'm doing wrong?</p>
  
  <pre><code>&lt;asp:TemplateField HeaderText="Quantity"&gt;
          &lt;ItemTemplate&gt;
              &lt;asp:Label ID="lblQuantity" runat="server" Text='&lt;%# Bind("Quantity") %&gt;'&gt;&lt;/asp:Label&gt;
          &lt;/ItemTemplate&gt;
          &lt;EditItemTemplate&gt;
              &lt;asp:TextBox ID="tbQuantity" runat="server" Text='&lt;%# Bind("Quantity") %&gt;'&gt;&lt;/asp:TextBox&gt;
          &lt;/EditItemTemplate&gt;
      &lt;/asp:TemplateField&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>public static bool UpdateShopCartQuantity(int intProductID, int intQuantity)
  {
      bool retStatus = false;
      // get shopping data from Session
      DataTable shoppingCartDataTable = (DataTable)HttpContext.Current.Session["Cart"];
  
      //  Find if ProductID already exists in Shopping Cart 
      DataRow dr1 = shoppingCartDataTable.Rows.Find(intProductID);
      if (dr1 != null)
      {
          // remove item if quantity is 0
          if (intQuantity == 0)
              dr1.Delete();
          else
          {
              dr1["Quantity"] = intQuantity;
          }
          // store back shopping cart in session
          HttpContext.Current.Session["Cart"] = shoppingCartDataTable;
          retStatus = true;
      }
      return retStatus;
  }    
  
  protected void gvCart_RowUpdating(object sender, GridViewUpdateEventArgs e)
  {
      int selectedRow = e.RowIndex;
      //get ProductID
      int productID = (int)gvCart.DataKeys[selectedRow].Value;
      //get current grid row
      GridViewRow row = (GridViewRow)gvCart.Rows[selectedRow];
  
      TextBox tQuantity = (TextBox)row.FindControl("tbQuantity");
      int intQty = Convert.ToInt32(tQuantity.Text);
      //get shopping cart from Session
      DataTable shoppingCartDataTable = (DataTable)Session["Cart"];
  
      if (clsShopCart.UpdateShopCartQuantity(productID, intQty) == false)
          lblError.Text = "Update Cart fail";
      else
          lblError.Text = "Update Cart done";
  
      //switch to view mode
      gvCart.EditIndex = -1;
      bindGridShopCart();
      lblTotal.Text = "Total: " + clsShopCart.GetShopCartTotalPrice().ToString("C");
  }
  </code></pre>