shopitem.aspx.cs

来自「ASP.NET2.0(C#篇)经典教程的源码...本源码很好的实现了购物车...」· CS 代码 · 共 29 行

CS
29
字号
using System;
using System.Web;
using System.Web.UI.WebControls;
using Wrox.Commerce;

partial class ShopItem : System.Web.UI.Page
{
  protected void btnAddToCart_Click( object sender, System.Web.UI.ImageClickEventArgs e)
  {
    double Price = double.Parse(((Label)FormView1.FindControl("PriceLabel")).Text);
    string ProductName = ((Label)FormView1.FindControl("NameLabel")).Text;
    string PictureURL = ((Label)FormView1.FindControl("PictureUrlLabel")).Text;
    int ProductID = Convert.ToInt32(Request.QueryString["ProductID"]);

    // create the cart if it doesn't already exist
    if ( Profile.Cart == null )
      Profile.Cart = new Wrox.Commerce.ShoppingCart();

    // insert the item
    // if the item already exists in the cart, 1 will be added to the quantity

    Profile.Cart.Insert(ProductID, Price, 1, ProductName, PictureURL);

    // return back to the main shop page
    Server.Transfer("Shop.aspx");
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?