当前位置: 首页>>代码示例>>C#>>正文


C# ShoppingCart.AddBookItemToShoppingCart方法代码示例

本文整理汇总了C#中ShoppingCart.AddBookItemToShoppingCart方法的典型用法代码示例。如果您正苦于以下问题:C# ShoppingCart.AddBookItemToShoppingCart方法的具体用法?C# ShoppingCart.AddBookItemToShoppingCart怎么用?C# ShoppingCart.AddBookItemToShoppingCart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ShoppingCart的用法示例。


在下文中一共展示了ShoppingCart.AddBookItemToShoppingCart方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: gridview_ShoppingCart_OnRowCommand

    /// <summary>
    /// 控件动作监听模块
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gridview_ShoppingCart_OnRowCommand(object sender, GridViewCommandEventArgs e)
    {
        ShoppingCart shoppingCart = new ShoppingCart();
        //获取到用户购物车
        if (Session["ShoppingCart"] != null)
        {
            shoppingCart = (ShoppingCart)Session["ShoppingCart"];
        }

        if (e.CommandName == "Plus" || e.CommandName == "Reduce" || e.CommandName == "DeleteBook")
        {
            int index = Convert.ToInt32(e.CommandArgument);//获取到当前索引
            Label lbl_bookAmount = (Label)gridview_ShoppingCart.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("lblSCBookNum");
            BookItem bookItem = shoppingCart.bookItemList[index];//获取需要变化数量的图书


            if (e.CommandName == "Plus")
            {

                lbl_bookAmount.Text = (Convert.ToInt32(lbl_bookAmount.Text) + 1).ToString();//增加label的值
                shoppingCart.AddBookItemToShoppingCart(bookItem);//将图书添加到购物车
            }

            if (e.CommandName == "Reduce")
            {
                if (bookItem.bookAmount > 1)
                {
                    lbl_bookAmount.Text = (Convert.ToInt32(lbl_bookAmount.Text) - 1).ToString();//减小label的值
                    shoppingCart.DeleteBookItemFromShoppingCart(bookItem);//将图书添加到购物车
                }
            }

            if (e.CommandName == "DeleteBook")
            {

                shoppingCart.DeleteBookItemFromShoppingCart_(bookItem);//删除选定的图书
                gridview_ShoppingCart.DataSource = shoppingCart.bookItemList;
                gridview_ShoppingCart.DataBind();//刷新购物车
            }

        }
    }
开发者ID:sduxzh,项目名称:OnlineBookStore_1.0,代码行数:47,代码来源:UserShoppingCart.aspx.cs


注:本文中的ShoppingCart.AddBookItemToShoppingCart方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。