我将创建一个会话并存储在类文件中,当我单击按钮时添加到购物车。通过使用gridview之后显示。任何人都可以给我一个简单的概念。我几乎放弃这样做因为我不知道。我要加入数据库lolz。当我点击一个按钮添加到购物车的代码是否正确?因为我新来自asp.net。如何在gridview上显示?会话传递给Class文件并通过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;
你会得到什么错误? – aw04
Cart.Item(string id,string name,Decimal price,int quantity)(+1 overload(s)) 错误 最好的重载方法匹配'E_Commerce.CartItem.CartItem(string,string,decimal,int)'有一些无效的参数 – Mickey