📄 basket.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Basket : System.Web.UI.Page
{
ShoppingCart cart;
void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
cart = ShoppingCartManager.GetCart();
BindCart();
}
else
{
UpdateQuantities();
}
}
void BindCart()
{
if(cart.ItemCount>0){
dgBasket.DataSource = cart.Items;
dgBasket.DataBind();
}else{
pnlCheckout.Visible=false;
}
}
protected void UpdateQuantities()
{
TextBox t = null;
string sProductID="";
int newQuantity = 0;
int productID=0;
//start with the second row, which is not the header
for (int i = 0; i < dgBasket.Rows.Count; i++)
{
//get the quantities from the grid
sProductID = dgBasket.Rows[i].Cells[0].Text;
productID = int.Parse(sProductID);
t = (TextBox)dgBasket.Rows[i].Cells[4].FindControl("txtQuantity");
newQuantity = int.Parse(t.Text);
if (newQuantity == 0)
{
//remove the item
ShoppingCartManager.RemoveItem(productID);
}
else
{
//update the profile
ShoppingCartManager.AdjustQuantity(productID, newQuantity);
}
}
//redirect to current page to refresh the basket
//and disable refresh problem
Response.Redirect("Basket.aspx");
}
protected void Remove_Item(object sender, GridViewDeleteEventArgs e)
{
//the productID is the first column, get the value and delete the item
//from the basket
string sProductID = dgBasket.Rows[e.RowIndex].Cells[0].Text;
int productID = int.Parse(sProductID);
ShoppingCartManager.RemoveItem(productID);
//redirect to current page to refresh the basket
//and disable refresh problem
Response.Redirect("basket.aspx");
}
protected void DoCommand(object sender, GridViewCommandEventArgs e)
{
}
protected void dgBasket_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -