1 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" PageSize="5"
2 寬度=“726px”AllowPaging=“True”AllowSorting=“True”
3 DataKeyNames =“DB1_1,DB1_2”OnRowDeleting =“GridView1_RowDeleting”OnPageIndexChanging =“GridView1_PageIndexChanging”OnRowDataBound =“GridView1_RowDataBound”OnSorting =“GridView1SortBound =“GridView1_RowDataBound”OnSorting =“GridView.
4 <列>
5 <asp:TemplateField HeaderText="序號" >
6 <專案模板>
7 <%# this.GridView1.PageIndex * this.GridView1.PageSize + this.GridView1.Rows.Count + 1%>
8 </項目範本>
9 </asp:模板欄位>
10 <asp:TemplateField HeaderText="選擇" >
11 <項目模板>
12 <asp:CheckBox ID="chkSelect" runat="server" ></asp:CheckBox>
13 </項目模板>
14 </asp:模板欄位>
15 <asp:TemplateField HeaderText="操作" ShowHeader="False">
16 <專案模板>
17 <asp:LinkButton ID="lbtnDelete" runat="server" CausesValidation="False" CommandName="Delete"
18 Text="刪除" OnClientClick="return recognize('確認要刪除嗎?');"></asp:LinkButton>
19 </項目模板>
20 </asp:模板欄位>
21 </列>
22 <AlternatingRowStyle BackColor="海藍寶石" />
23 </asp:GridView>
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 字串strDelete = "";
4 for (int i = 0; i < this.GridView1.Rows.Count; i++)
5 {
6字串標籤;
7 bool isChecked = ((CheckBox)GridView1.Rows[i].FindControl("chkSelect")).Checked;
8 標籤 = ((Label)GridView1.Rows[i].FindControl("labXH")).Text;
9 如果(已選取)
10 {
11 strDelete = "DB1_1" + "=" + 標籤;
12}
13}
14 conn.RunSql("從 DB1 其中刪除" + strDelete
15 this.chkSelectAll.Checked = false;
16 GridViewBind();
17}
18
19 protected void chkSelectAll_CheckedChanged(物件發送者,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}