Exemplo n.º 1
0
        protected void dltAllItems_ItemCommand(object source, DataListCommandEventArgs e)
        {
            string productID = Convert.ToString(e.CommandArgument);
            int    cartItems = 0;

            Label lblCart = (Label)this.Master.FindControl("lblCart");

            foreach (DataListItem item in dltAllItems.Items)
            {
                HiddenField hdnProductID = (HiddenField)item.FindControl("hdnProductID");

                if (hdnProductID.Value == productID)
                {
                    TextBox txtQty = (TextBox)item.FindControl("txtQty");

                    bool isValidNumber = objBAL.CheckIsValidNumber(txtQty.Text);

                    if (!isValidNumber)
                    {
                        Panel pnlQtyErr = (Panel)item.FindControl("pnlQtyErr");
                        pnlQtyErr.Visible = true;
                    }
                    else
                    {
                        if (Convert.ToInt32(txtQty.Text) > 0)
                        {
                            Panel pnlQtyErr = (Panel)item.FindControl("pnlQtyErr");
                            pnlQtyErr.Visible = false;

                            if (Session["ShoppingCart"] == null || Session["ShoppingCart"].ToString().Trim().Length <= 0)
                            {
                                string shoppingCart = productID + "|@|" + txtQty.Text;
                                Session["ShoppingCart"] = shoppingCart;

                                lblCart.Text = Convert.ToString(UserScript1.FillCart()) + " items";
                            }
                            else
                            {
                                string shoppingCart = Session["ShoppingCart"].ToString();
                                shoppingCart           += "|@|" + productID + "|@|" + txtQty.Text;
                                Session["ShoppingCart"] = shoppingCart;

                                lblCart.Text = Convert.ToString(UserScript1.FillCart()) + " items";
                            }
                        }
                    }

                    break;
                }
            }
        }