前台代码:
<asp:GridView runat="server" ID="GridView1"> <Columns> <asp:TemplateField> <HeaderTemplate> <asp:CheckBox runat="server" ID="CheckAll" AutoPostBack="True" OnCheckedChanged="CheckAll_CheckedChanged"/> </HeaderTemplate> <ItemTemplate> <asp:CheckBox runat="server" ID="CheckItem"/> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
后台代码:
protected void CheckAll_CheckedChanged(object sender,EventArgs e) { for(int i = ; i < this.GridView1.Rows.Count;i++) { ((CheckBox)GridView1.Rows[i].FindControl("CheckItem")).Checked=((CheckBox)this.GridView1.HeaderRow.FindControl("CheckAll")).Checked; } }
版权声明:除特别声明外,本站所有文章皆是本站原创,转载请以超链接形式注明出处!