this.DataList1.DataSource=(Hashtable)Session["bus"];//直接利用哈希表作为数据源,
this.DataList1.DataBind();//绑定一下 www.knowsky.com
更新数量
1private void LinkButton1_Click(object sender, System.EventArgs e)
2 {
3
4 foreach(DataListItem dl in this.DataList1.Items)//遍历集合
5 {
6 TextBox tb=(TextBox)dl.FindControl("TextBox1");//找到文本框
7 int newpid=Convert.ToInt32(tb.Text.ToString());//查出文本框里面的值
8
9 Label label1=(Label)dl.FindControl("key");//找到装载哈希表key字段的那个控件
10 string pid=label1.Text.ToString();//把他的值拿出来
11
12 Hashtable ht=(Hashtable)Session["bus"];//把session["bus"]对象赋值给哈希表 ht
13 int oldpid=(int)ht[pid];//求得原来的数量
14
15 if(newpid!=oldpid)//如果文本框里的值不等于原来的数量,就用新的更换到哈希表中的值
16 {
17 ht[pid]=newpid;
18 }
19 Session["bus"]=ht;//最后再更新Session 对象
20 }
21 }
出处:.net入门ing…… BLOG