1 <asp:CheckBox ID="chkSelectAll" runat="server" Text="全部選中" OnCheckedChanged="chkSelectAll_CheckedChanged" AutoPostBack="True" ></ASP:CheckBox>
2 <ASP:Button ID="btnDelete" runat="server" Text="刪除" OnClick="btnDelete_Click" />
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 }