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 =“GridView1_Sorting”高度=“279px”>
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}