【发布时间】:2013-11-24 03:41:41
【问题描述】:
当我单击添加到购物车的按钮时,我将创建一个会话并存储在类文件中。之后使用 gridview 显示。任何人都可以给我一个简单的概念。我几乎放弃这样做,因为我不知道。我要添加到数据库lolz。当我单击按钮添加到购物车时,代码是否正确?因为我是 asp.net 的新手。如何在gridview上显示?
我的类文件出错了
/*missiong partial modifier on declaration of type'E-commerce_shoppingCart';
another partial declaration of this type exists
public class ShoppingCart
{
//Consists of a Price (the sum of all of your items)
public decimal Total { get { return Items.Sum(i => i.Subtotal); } }
//The total number of items in your cart
public int TotalItems { get { return Items.Count; } }
//A Collection of "Cart Items"
public List<CartItem> Items { get; set; }
//Basic constructor
public ShoppingCart()
{
Items = new List<CartItem>();
}
}
//A Shopping Cart Item
public class CartItem
{
public string ItemID { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public int Quantity { get; set; }
//Returns the subtotal (price * quantity)
public decimal Subtotal { get { return Price * Quantity; } }
public CartItem()
{
}
//Constructor that accepts your items
public CartItem(string id, string name, decimal price, int quantity)
{
ItemID = id;
Name = name;
Price = price;
Quantity = quantity;
}
}
在我的产品详细信息页面我应该如何创建一个会话,并一个一个存储,因为有一些 contitions
if (Session["Cart"] == null)
{
Session["Cart"] = new ShoppingCart();
}
ShoppingCart cart = Session["Cart"] as ShoppingCart;
//below correct? need to put else? how to store one by one
cart.Items.Add(new CartItem(Id, lblName.Text, Decimal.Parse(lblPrice.Text), int.Parse(txtAddtoCart.Text)));
//how should i store at class file, my id is passing from query string, assuming now is static
Session["Cart"] = cart;
【问题讨论】:
-
你得到什么错误?
-
Cart.Item(string id,string name,Decimal price,int quantity) (+1 重载) 错误最佳重载方法匹配'E_Commerce.CartItem.CartItem(string, string,decimal ,int)' 有一些无效参数
标签: c# asp.net class datagridview shopping-cart