GridView CheckBox当翻页时保存选中的项(viewstate)
来源:互联网 发布:月相手表 知乎 编辑:程序博客网 时间:2024/05/21 14:54
1 属性 保存全选的项#region 属性 保存全选的项
2
3 protected ArrayList SelectedItems
4 {
5 get
6 {
7 if (ViewState["SelectedItems"] == null)
8 {
9 ViewState["SelectedItems"] = new ArrayList();
10 }
11
12 return ViewState["SelectedItems"] as ArrayList;
13 }
14 set
15 {
16 ViewState["SelectedItems"] = value;
17 }
18 }
19 /**//// <summary>
20 /// 页面加载
21 /// </summary>
22 /// <param name="sender"></param>
23 /// <param name="e"></param>
24 protected void Page_Load(object sender, EventArgs e)
25 {
26 SaveSelectedItems();
27 if (!IsPostBack)
28 {
29 if (myGridView.Attributes["SortExpression"] == null)
30 {
31 myGridView.Attributes["SortExpression"] = "DAID";
32 myGridView.Attributes["SortDirection"] = "asc";
33 }
34 BindDynamicAccountFlowInfo();
35 }
36 }
37 /**//// <summary>
38 /// 保存页面选中的项
39 /// </summary>
40 private void SaveSelectedItems()
41 {
42 for (int i = 0; i < myGridView.Rows.Count; i++)
43 {
44 CheckBox tempCheckBox = myGridView.Rows[i].FindControl("chkSelect") as CheckBox;
45 string id = myGridView.Rows[i].Cells[0].Text;
46
47 if (SelectedItems.Contains(id) && !tempCheckBox.Checked)
48 {
49 SelectedItems.Remove(id);
50 }
51 if (!SelectedItems.Contains(id) && tempCheckBox.Checked)
52 {
53 SelectedItems.Add(id);
54 }
55 }
56 }
57 /**//// <summary>
58 /// 行绑定
59 /// </summary>
60 /// <param name="sender"></param>
61 /// <param name="e"></param>
62 protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
63 {
64 if (e.Row.RowType == DataControlRowType.DataRow)
65 {
66 if (e.Row.RowIndex > -1 && SelectedItems.Count > 0)
67 {
68 CheckBox tempCheckBox = e.Row.FindControl("chkSelect") as CheckBox;
69 string id = e.Row.Cells[0].Text;
70 if (SelectedItems.Contains(id))
71 {
72 tempCheckBox.Checked = true;
73 }
74 else
75 {
76 tempCheckBox.Checked = false;
77 }
78 }
79 }
80
81 }
82 /**//// <summary>
83 /// 删除按钮
84 /// </summary>
85 /// <param name="sender"></param>
86 /// <param name="e"></param>
87 protected void btnDelAll_ServerClick(object sender, EventArgs e)
88 {
89 string sID = "";//选中删除所有行的id
90
91 foreach (string tempString in SelectedItems)
92 {
93 sID += tempString + ",";
94 }
95 if (SelectedItems.Count < 1)
96 {
97 ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('你没有选择!!!')</script>");
98 }
99 else
100 {
101 daDB.DelDynamicAccountFlowinfo(sID.Substring(0, sID.Length - 1));
102 }
103 if (Cache["dataSource"] != null)
104 Cache.Remove("dataSource");//***先清空原有页面缓存
105
106 BindDynamicAccountFlowInfo();
107 }
108下面是删除操作代码(DB):
2
3 protected ArrayList SelectedItems
4 {
5 get
6 {
7 if (ViewState["SelectedItems"] == null)
8 {
9 ViewState["SelectedItems"] = new ArrayList();
10 }
11
12 return ViewState["SelectedItems"] as ArrayList;
13 }
14 set
15 {
16 ViewState["SelectedItems"] = value;
17 }
18 }
19 /**//// <summary>
20 /// 页面加载
21 /// </summary>
22 /// <param name="sender"></param>
23 /// <param name="e"></param>
24 protected void Page_Load(object sender, EventArgs e)
25 {
26 SaveSelectedItems();
27 if (!IsPostBack)
28 {
29 if (myGridView.Attributes["SortExpression"] == null)
30 {
31 myGridView.Attributes["SortExpression"] = "DAID";
32 myGridView.Attributes["SortDirection"] = "asc";
33 }
34 BindDynamicAccountFlowInfo();
35 }
36 }
37 /**//// <summary>
38 /// 保存页面选中的项
39 /// </summary>
40 private void SaveSelectedItems()
41 {
42 for (int i = 0; i < myGridView.Rows.Count; i++)
43 {
44 CheckBox tempCheckBox = myGridView.Rows[i].FindControl("chkSelect") as CheckBox;
45 string id = myGridView.Rows[i].Cells[0].Text;
46
47 if (SelectedItems.Contains(id) && !tempCheckBox.Checked)
48 {
49 SelectedItems.Remove(id);
50 }
51 if (!SelectedItems.Contains(id) && tempCheckBox.Checked)
52 {
53 SelectedItems.Add(id);
54 }
55 }
56 }
57 /**//// <summary>
58 /// 行绑定
59 /// </summary>
60 /// <param name="sender"></param>
61 /// <param name="e"></param>
62 protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
63 {
64 if (e.Row.RowType == DataControlRowType.DataRow)
65 {
66 if (e.Row.RowIndex > -1 && SelectedItems.Count > 0)
67 {
68 CheckBox tempCheckBox = e.Row.FindControl("chkSelect") as CheckBox;
69 string id = e.Row.Cells[0].Text;
70 if (SelectedItems.Contains(id))
71 {
72 tempCheckBox.Checked = true;
73 }
74 else
75 {
76 tempCheckBox.Checked = false;
77 }
78 }
79 }
80
81 }
82 /**//// <summary>
83 /// 删除按钮
84 /// </summary>
85 /// <param name="sender"></param>
86 /// <param name="e"></param>
87 protected void btnDelAll_ServerClick(object sender, EventArgs e)
88 {
89 string sID = "";//选中删除所有行的id
90
91 foreach (string tempString in SelectedItems)
92 {
93 sID += tempString + ",";
94 }
95 if (SelectedItems.Count < 1)
96 {
97 ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('你没有选择!!!')</script>");
98 }
99 else
100 {
101 daDB.DelDynamicAccountFlowinfo(sID.Substring(0, sID.Length - 1));
102 }
103 if (Cache["dataSource"] != null)
104 Cache.Remove("dataSource");//***先清空原有页面缓存
105
106 BindDynamicAccountFlowInfo();
107 }
108下面是删除操作代码(DB):
1 public bool DelDynamicAccountFlowinfo(string sID)
2 {
3 string sqlstr=string.Format("delete from DynamicAccountFlow where DAFID IN({0})", sID);
4 conn = Myconn.SqlConnection;
5 SqlCommand mycommand = new SqlCommand(sqlstr, conn);
6 mycommand.CommandType = CommandType.Text;
7 mycommand.CommandText = sqlstr;
8 conn.Open();
9 mycommand.ExecuteNonQuery();
10 conn.Close();
11 return true;
12 }
2 {
3 string sqlstr=string.Format("delete from DynamicAccountFlow where DAFID IN({0})", sID);
4 conn = Myconn.SqlConnection;
5 SqlCommand mycommand = new SqlCommand(sqlstr, conn);
6 mycommand.CommandType = CommandType.Text;
7 mycommand.CommandText = sqlstr;
8 conn.Open();
9 mycommand.ExecuteNonQuery();
10 conn.Close();
11 return true;
12 }
- GridView CheckBox当翻页时保存选中的项(viewstate)
- GridView翻页记住选中的checkbox
- GridView翻页记住选中的checkbox
- GridView中CheckBox 翻页保存
- 保存GridView checkbox 选中的状态(Session)
- 实现GridView翻页并且实现CheckBox选中功能的保持
- GridView中的CheckBox 翻页时记录选中状态
- 关于GridView翻页checkBox状态保存的问题
- 关于GridView翻页checkBox状态保存的问题 (session)
- 关于GridView翻页checkBox状态保存的问题
- 关于GridView翻页checkBox状态保存的问题
- GridView 翻页后保持checkbox选中状态
- jQuery 操作checkbox翻页保存选中状态
- 翻页时保存checkbox的值
- GridView CheckBox 翻页不保存状态
- Gridview中checkbox选中时获取当前行id
- 点击Gridview行,选中/取消选中,当前行中的Checkbox
- GridView 如何在翻页时保持CheckBox的选择
- Sqlite的FAQ学习
- AVENGINE.exe
- NDoc2005体验 [内容转自csdn.kolacowboy/archive]
- 模板类-安全链表 SafeList
- Sqlite内存数据库在多线程下的使用问题
- GridView CheckBox当翻页时保存选中的项(viewstate)
- 失败教训:可口可乐百年来最大的营销失误
- symfony03_3:探索symfony代码
- avgamsvr.exe
- sybase for linux 安装一
- FireFox不支持disable-output-escaping解决办法
- 毕业了,找工作ing!
- SOA介绍
- 周星驰:卑微是人生第一课