1<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"PageSize="5"
2Width="726px"AllowPaging="True"AllowSorting="True"
3DataKeyNames="DB1_1,DB1_2"OnRowDeleting="GridView1_RowDeleting"OnPageIndexChanging="GridView1_PageIndexChanging"OnRowDataBound="GridView1_RowDataBound"OnSorting="GridView1_Sorting"Height="279px">
4<Columns>
5<asp:TemplateFieldHeaderText="序号">
6<ItemTemplate>
7<%#this.GridView1.PageIndex*this.GridView1.PageSize+this.GridView1.Rows.Count+1%>
8</ItemTemplate>
9</asp:TemplateField>
10<asp:TemplateFieldHeaderText="选择">
11<ItemTemplate>
12<asp:CheckBoxID="chkSelect"runat="server"></asp:CheckBox>
13</ItemTemplate>
14</asp:TemplateField>
15<asp:TemplateFieldHeaderText="操作"ShowHeader="False">
16<ItemTemplate>
17<asp:LinkButtonID="lbtnDelete"runat="server"CausesValidation="False"CommandName="Delete"
18Text="删除"OnClientClick="returnconfirm('确认要删除吗?');"></asp:LinkButton>
19</ItemTemplate>
20</asp:TemplateField>
21</Columns>
22<AlternatingRowStyleBackColor="Aquamarine"/>
23</asp:GridView>
1<asp:CheckBoxID="chkSelectAll"runat="server"Text="全部选中"OnCheckedChanged="chkSelectAll_CheckedChanged"AutoPostBack="True"></asp:CheckBox>
2<asp:ButtonID="btnDelete"runat="server"Text="删除"OnClick="btnDelete_Click"/>
1protectedvoidbtnDelete_Click(objectsender,EventArgse)
2{
3stringstrDelete="";
4for(inti=0;i<this.GridView1.Rows.Count;i++)
5{
6stringLabel;
7boolisChecked=((CheckBox)GridView1.Rows[i].FindControl("chkSelect")).Checked;
8Label=((Label)GridView1.Rows[i].FindControl("labXH")).Text;
9if(isChecked)
10{
11strDelete="DB1_1"+"="+Label;
12}
13}
14conn.RunSql("DeletefromDB1where"+strDelete
15this.chkSelectAll.Checked=false;
16GridViewBind();
17}
18
19protectedvoidchkSelectAll_CheckedChanged(objectsender,EventArgse)
20{
21//遍历GridView行获取CheckBox属性
22for(inti=0;i<this.GridView1.Rows.Count;i++)
23{
24((CheckBox)GridView1.Rows[i].FindControl("chkSelect")).Checked=this.chkSelectAll.Checked;
25}
26}