商品显示页面的cs页面中的代码如下:
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName.Equals("detailSee"))
{
AddressBack(e);
}
else if (e.CommandName.Equals("buy"))
{
AddShopCart(e);
}
}
public void AddressBack(DataListCommandEventArgs e)
{
Session["address"] = "";
Session["address"] = "ProNew.aspx";
Response.Redirect("~/Product/ProductDetail.aspx?ID="+Convert.ToInt32(e.CommandArgument.ToString()));
}
public void AddShopCart(DataListCommandEventArgs e)
{
Hashtable hashCar;
if (Session["ShopCart"] == null)
{
hashCar = new Hashtable();
hashCar.Add(e.CommandArgument, 1);
Session["ShopCart"] = hashCar;
}
else
{
hashCar = (Hashtable)Session["ShopCart"];
if (hashCar.Contains(e.CommandArgument))
{
int count = Convert.ToInt32(hashCar[e.CommandArgument].ToString());
hashCar[e.CommandArgument] = (count + 1);
}
else
hashCar.Add(e.CommandArgument, 1);
}
}
protected void Button2_Click(object sender, EventArgs e)
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName.Equals("detailSee"))
{
AddressBack(e);
}
else if (e.CommandName.Equals("buy"))
{
AddShopCart(e);
}
}
public void AddressBack(DataListCommandEventArgs e)
{
Session["address"] = "";
Session["address"] = "ProNew.aspx";
Response.Redirect("~/Product/ProductDetail.aspx?ID="+Convert.ToInt32(e.CommandArgument.ToString()));
}
public void AddShopCart(DataListCommandEventArgs e)
{
Hashtable hashCar;
if (Session["ShopCart"] == null)
{
hashCar = new Hashtable();
hashCar.Add(e.CommandArgument, 1);
Session["ShopCart"] = hashCar;
}
else
{
hashCar = (Hashtable)Session["ShopCart"];
if (hashCar.Contains(e.CommandArgument))
{
int count = Convert.ToInt32(hashCar[e.CommandArgument].ToString());
hashCar[e.CommandArgument] = (count + 1);
}
else
hashCar.Add(e.CommandArgument, 1);
}
}
protected void Button2_Click(object sender, EventArgs e)