protected void Button1_Click(object sender, EventArgs e)
        {
            bool found = false;

            foreach (GridViewRow row in CartList.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    CheckBox cb = row.FindControl("Remove") as CheckBox;
                    if (cb.Checked == true)
                    {
                        int cartItemID = Convert.ToInt32(row.Cells[0].Text);
                        CartActions.DeleteCartItem(cartItemID);
                        found = true;
                    }
                }
            }
            Label1.Visible = true;
            if (found == true)
            {
                Label1.Text = "Cart Items removed succcessfully....";
                UpdateCart();
            }
            else
            {
                Label1.Text = "Nothing selected...";
            }
        }
 private void UpdateCart()
 {
     CartList.DataSource = CartActions.GetCart();
     CartList.DataBind();
     if (CartList.Rows.Count > 0)
     {
         Label lbltotal = CartList.FooterRow.Cells[4].FindControl("lblTotal") as Label;
         lbltotal.Text = CartActions.GetCart().Sum(a => a.LineTotal).ToString("c");
     }
 }
        protected void Button2_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow row in CartList.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    int cartItemID = Convert.ToInt32(row.Cells[0].Text);
                    int qty        = Convert.ToInt32((row.Cells[3].FindControl("PurchaseQuantity") as TextBox).Text);

                    CartActions.UpdateQuantity(cartItemID, qty);
                    Label1.Visible = true;
                    Label1.Text    = "Cart Items updated succcessfully....";
                    UpdateCart();
                }
            }
        }
Пример #4
0
        protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
        {
            if (e.CommandName == "AddToCart")
            {
                int     productid   = Convert.ToInt32((e.Item.FindControl("ProductIDLabel") as Label).Text);
                string  productname = (e.Item.FindControl("ProductNameLabel") as Label).Text;
                Label   lbl         = e.Item.FindControl("UnitPriceLabel") as Label;
                decimal unitprice   = Decimal.Parse(lbl.Text, NumberStyles.AllowCurrencySymbol | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands, new CultureInfo("en-US"));

                CartActions.SaveCartItem(new CartItem()
                {
                    ProductID = productid, ProductName = productname, UnitPrice = unitprice, Quantity = 1
                });
                Label1.Text    = "Product saved successfully in the cart.";
                Label1.Visible = true;
            }
        }