protected void gvProducts_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            cartItems = new List<cartItem>();
            cartItems = (List<cartItem>)Session["cart"];
            int row = Convert.ToInt32(e.CommandArgument);
            cartTotal = (double)Session["cartTotal"];

            if (e.CommandName == "btnAdd")
            {
                if (((TextBox)gvProducts.Rows[row].FindControl("txtQuantity")).Text == "")
                {
                    lblAddQuantity.Text = "* Please enter quantity";
                }
                else
                {
                    int prodNum = Convert.ToInt32(gvProducts.Rows[row].Cells[0].Text);
                    string desc = gvProducts.Rows[row].Cells[1].Text;
                    double price = double.Parse(gvProducts.Rows[row].Cells[2].Text, NumberStyles.Currency);

                    string image = getImageURL(prodNum);
                    int quantity = Convert.ToInt32(((TextBox)gvProducts.Rows[row].FindControl("txtQuantity")).Text);
                    double subTotal = price * quantity;
                    cartItem c = new cartItem(prodNum, desc, price, quantity, subTotal, image);
                    cartTotal += subTotal;
                    cartItems.Add(c);
                    Session["cartTotal"] = cartTotal;
                    lblAddQuantity.Text = "Added '"+desc+"' Successfully";
                }
            }
        }
Example #2
0
 public void addToCart(cartItem cI, List<object> list)
 {
     list.Add(cI);
 }