コード例 #1
0
        public static CartItemsList GetCart()
        {
            CartItemsList cart = (CartItemsList)HttpContext.Current.Session["Cart"];

            if (cart == null)
            {
                HttpContext.Current.Session["Cart"] = new CartItemsList();
            }
            return((CartItemsList)HttpContext.Current.Session["Cart"]);
        }
コード例 #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     // retrieve cart object from session state on every postback
     cart = CartItemsList.GetCart();
     // on initial page load, add cart items to list control
     if (!IsPostBack)
     {
         this.DisplayCart();
     }
 }
コード例 #3
0
        protected void BtnAdd_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                //get cart from session state and selected item from cart
                CartItemsList cart = CartItemsList.GetCart();

                if (selectedMobile != null)
                {
                    cart.AddItem(selectedMobile, Convert.ToInt32(txtQuantity.Text));
                    Response.Redirect("~/Cart.aspx");
                }
            }
        }