国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - ASP.NET教程 - asp.net基于HashTable實(shí)現(xiàn)購物車的方法

asp.net基于HashTable實(shí)現(xiàn)購物車的方法

2019-12-29 13:27happy664618843 ASP.NET教程

這篇文章主要介紹了asp.net基于HashTable實(shí)現(xiàn)購物車的方法,涉及asp.net中HashTable結(jié)合session實(shí)現(xiàn)購物車功能的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實(shí)例講述了asp.net基于HashTable實(shí)現(xiàn)購物車的方法。分享給大家供大家參考,具體如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//用戶購買商品時
if (e.CommandName.ToLower() == "buy")
{
 //判斷用戶購物車是否為空 如果為空則分配一個
 Hashtable table;
 if (Session["car"] == null)
 {
  table = new Hashtable();
 }
 else
 {
  //用戶購物車己存在 則取出數(shù)據(jù)
  table = Session["car"] as Hashtable;
 }
 //如果用戶購物車中不包括該商品信息 則添加一個新商品
 if (!table.Contains(e.CommandArgument))
 {
  table.Add(e.CommandArgument, 1);//添加一個新商品 數(shù)量為1
 }
 else
 {
  //如果購物車己存在該商品信息 則將該商品的數(shù)量加1 根據(jù)HashTable的鍵獲取相對應(yīng)的值
  int count = Convert.ToInt32(table[e.CommandArgument].ToString());
  //給該商品數(shù)量加上1
  table[e.CommandArgument] = (count + 1);
 }
 //保存商品信息
 Session["car"] = table;
 Response.Redirect("shoppingcar.aspx");
}
//商品信息列表
private void shoplist()
{
  Hashtable table;
  if (Session["car"] == null)
  {
   table = new Hashtable();
  }
  else
  {
   table = Session["car"] as Hashtable;
  }
  if (table.Count == 0)
  {
   Image13.Visible = true;
   Msg.Visible = true;
   Msg.Text = "<b style="color:red" mce_style="color:red">您還沒有購物呢?趕快購物吧!</b>";
  }
  string[] Arrkey = new string[table.Count];
  int[] ArrVal = new int[table.Count];
  table.Keys.CopyTo(Arrkey, 0);
  table.Values.CopyTo(ArrVal, 0);
  //定義字符串 形成 ('1,2,3')
  string Products = "('";
  int k = 0;
  for (int j = 0; j < Arrkey.Length; j++)
  {
   if(k>0)Products += "','"; k++;
   Products += Arrkey.GetValue(j).ToString();
  }
  Products += "')";
  DataSet ds = productbll.GetInfoByWhere(" pid in " + Products);
  DataTable Table1 = new DataTable();
  Table1 = ds.Tables[0];
  Table1.Columns.Add(new DataColumn("shuliang", System.Type.GetType("System.Int32")));
  //得到pid的值 并將它設(shè)置為Table1的主鍵
  DataColumn[] keys = { Table1.Columns["pid"]};
  Table1.PrimaryKey = keys;
  foreach (string key in table.Keys)
  {
   Table1.Rows.Find(key)["shuliang"] = table[key];//根據(jù)鍵獲取值 商品的數(shù)量
  }
  Table1.Columns.Add(new DataColumn("zongjia", System.Type.GetType("System.Double"), "hotprice*shuliang"));
  for (int n = 0; n < Table1.Rows.Count; n++)
  {
   tPrice +=Convert.ToDouble(Table1.Rows[n]["zongjia"]);
  }
  Label1.Text = tPrice.ToString();
  Session["total"] = Label1.Text.ToString();
  MyGrid.DataSource = Table1.DefaultView;
  MyGrid.DataBind();
}
#region 從購物車中刪除一條商品信息
protected void MyGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
  Hashtable table;
  if (Session["car"] == null)
  {
   table = new Hashtable();
  }
  else
  {
   table = Session["car"] as Hashtable;
  }
  //如果點(diǎn)擊刪除按鈕 則從購物車中移除該商品信息
  if (e.CommandName.ToLower() == "delete")
  {
   if (table.ContainsKey(e.CommandArgument))
   {
    //從HashTable中移除該商品的信息(商品編號) 鍵:為商品編號 值為:商品數(shù)量
    table.Remove(e.CommandArgument);
   }
   Msg.Text = (string)e.CommandArgument;
  }
  Session["car"] = table;
  //調(diào)用方法
  shoplist();
}
#endregion

希望本文所述對大家asp.net程序設(shè)計有所幫助。

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 日韩欧美中文字幕在线视频 | 中文在线日韩 | 黄色一级电影在线观看 | 国产欧美综合一区二区三区 | 99久久精品免费看国产四区 | 噜噜噜在线观看免费视频日本 | 国产亚洲精品美女久久久久久久久久 | 欧洲黄色 级黄色99片 | 午夜免费福利视频 | 久久久久久av | 黄色大片在线播放 | 男人的天堂在线免费视频 | 欧美wwwsss9999 | 久久久精品影院 | 午夜私人视频 | 午夜爱爱毛片xxxx视频免费看 | 欧美精品在线一区 | 91av国产视频 | 久久久免费 | 国产中文字幕在线看 | 99精品在线观看 | 国产成人精品一区 | 成人三级视频 | 午夜免费电影 | 久久综合久久综合久久综合 | 国产成年人在线观看 | 国产综合精品一区二区三区 | 国产精品一区久久 | 香蕉大人久久国产成人av | 亚洲精品成人天堂一二三 | 综合五月网 | 亚洲美女精品视频 | 99精品免费视频 | 成人高清视频在线观看 | 亚洲欧美综合乱码精品成人网 | 91大片在线观看 | 91捆绑91紧缚调教91 | 国产精品毛片久久久久久久 | 精品久久99 | 国产精品自拍视频 | 狠狠色狠狠色合久久伊人 |