コード例 #1
0
    //Delete the selected item
    protected void Cart_GridViewDelete(object sender, GridViewDeleteEventArgs e)
    {
        string     ItemNo   = Cart.DataKeys[e.RowIndex].Values[0].ToString();
        RaisedItem selected = cartitem.Where(item => item.ItemNo == ItemNo).FirstOrDefault();

        cartitem.Remove(selected);
        Session["session"] = cartitem;
        Cart.DataSource    = cartitem;
        Cart.DataBind();
    }
コード例 #2
0
    //Select the selected item
    protected void StationeryGridView_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridViewRow row  = StationeryGridView.SelectedRow;
        RaisedItem  cart = new RaisedItem();

        cart.ItemNo      = row.Cells[0].Text;
        cart.description = row.Cells[1].Text;
        string input = (row.Cells[2].FindControl("Quantity") as TextBox).Text.ToString();
        int    value;

        if (!int.TryParse(input, out value) || value < 0)
        {
            Msg.Text = "The input number has to be integer (greater than 0).";
        }
        else
        {
            Session["Test"] = row;
            Msg.Text        = "";
            cart.quantity   = (row.Cells[2].FindControl("Quantity") as TextBox).Text;

            bool isAlreadyInCart = false;
            foreach (var item in cartitem)
            {
                if (item.ItemNo.Equals(cart.ItemNo))
                {
                    int oldQty = Int32.Parse(item.quantity);
                    int newQty = Int32.Parse(cart.quantity);
                    item.quantity   = (oldQty + newQty).ToString();
                    isAlreadyInCart = true;
                    break;
                }
            }

            if (!isAlreadyInCart)
            {
                cartitem.Add(cart);
            }

            Session["session"] = cartitem;
            Cart.DataSource    = cartitem;
            Cart.DataBind();
            Confirm.Visible = true;
            Delete.Visible  = true;
        }
    }