protected void UpdateQty_Btn_Click(object sender, EventArgs e)
        {
            int rowCount = GridView1.Rows.Count;

            string productID;

            int newQty;

            bool success = true;

            GridViewRow gridRow;
            TextBox     qtyTextBox;

            for (int i = 0; i < rowCount; i++)
            {
                gridRow   = GridView1.Rows[i];                      // current row of the grid view
                productID = GridView1.DataKeys[i].Value.ToString(); // current data key from the grid view (0th row)

                qtyTextBox = (TextBox)gridRow.FindControl("editQty");

                if (Int32.TryParse(qtyTextBox.Text, out newQty))
                {
                    success = success && ShoppingCartAccess.UpdateItem(productID, newQty);
                }
                else
                {
                    success = false;
                }
            }

            cartUpdateStatusLabel.Text = success ? "The cart was successfully updated!!" : "Some quantity updates failed!! Please check your cart!!";

            PopulateControls();
        }
        protected void addToCart_Btn_Click(object sender, EventArgs e)
        {
            string prodID = Request.QueryString["ProductID"];

            string cartID;

            // if the user has a cart already, fetch their cartid from their machine(cookies)
            if (Request.Cookies["SportsStore_CartID"] != null)
            {
                cartID = Request.Cookies["SportsStore_CartID"].Value;
            }
            // if they dont have a cart already, generate a unique cartID for them and write on their machine
            else
            {
                cartID = Guid.NewGuid().ToString();

                HttpCookie cookie = new HttpCookie("SportsStore_CartID", cartID);

                TimeSpan timeSpan = new TimeSpan(10, 0, 0, 0);

                DateTime expirationDate = DateTime.Now.Add(timeSpan);

                cookie.Expires = expirationDate;

                Response.Cookies.Add(cookie);
            }

            ShoppingCartAccess.AddToCart(prodID, cartID);
        }
        public void PopulateControls()
        {
            DataTable dt = ShoppingCartAccess.GetCartItems();

            if (dt.Rows.Count > 0)
            {
                Label1.Text          = "These are the items in your cart: ";
                GridView1.DataSource = dt;
                GridView1.DataBind();

                decimal amount = ShoppingCartAccess.GetCartTotal();
                cartTotalLabel.Text = String.Format("{0:c}", amount);

                UpdateQty_Btn.Enabled = true;
            }
            else
            {
                Label1.Text       = "there are no items in your cart!!";
                GridView1.Visible = false;

                cartTotalLabel.Text   = "0";
                UpdateQty_Btn.Enabled = false;
            }
        }