繁体中文
设为首页
加入收藏
当前位置:.Net技术首页 >> Asp.Net开发 >> ASP.NET2.0下含有CheckBox的GridView删除选定记录实例!

ASP.NET2.0下含有CheckBox的GridView删除选定记录实例!

2007-09-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介:1 4 5 6 7 8 9 ...

1

2 Width="726px" AllowPaging="True" AllowSorting="True"

3 DataKeyNames="DB1_1,DB1_2" OnRowDeleting="GridView1_RowDeleting" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDataBound="GridView1_RowDataBound" OnSorting="GridView1_Sorting" Height="279px" >

4

5

6

7 <%# this.GridView1.PageIndex * this.GridView1.PageSize + this.GridView1.Rows.Count + 1%>

8

9

10

11

12

13

14

15

16

17

18 Text="删除" OnClientClick="return confirm('确认要删除吗?');">

19

20

21

22

23

1

2

1 protected void btnDelete_Click(object sender, EventArgs e)

2 {

3 string strDelete = "";

4 for (int i = 0; i < this.GridView1.Rows.Count; i++)

5 {

6 string Label;

7 bool isChecked = ((CheckBox)GridView1.Rows[i].FindControl("chkSelect")).Checked;

8 Label = ((Label)GridView1.Rows[i].FindControl("labXH")).Text;

9 if (isChecked)

10 {

11 strDelete = "DB1_1" + "=" + Label;

12 }

13 }

14 conn.RunSql("Delete from DB1 where " + strDelete

15 this.chkSelectAll.Checked = false;

16 GridViewBind();

17 }

18

19 protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)

20 {

21 //遍历GridView行获取CheckBox属性

22 for (int i = 0; i < this.GridView1.Rows.Count; i++)

23 {

24 ((CheckBox)GridView1.Rows[i].FindControl("chkSelect")).Checked = this.chkSelectAll.Checked;

25 }

26 }

责任编辑:admin
相关文章