日期:2014-05-17 浏览次数:20438 次
如题: 现要求所有操作在服务器端实现 请大家给出详细代码
protected void cbSelectAll_CheckedChanged(object sender, EventArgs e) { foreach (GridViewRow gvr in gvList.Rows) { ((CheckBox)gvr.Cells[0].FindControl("cbSelect")).Checked = ((CheckBox)sender).Checked; } } protected void btnDelete_Click(object sender, EventArgs e) { foreach (GridViewRow gvr in gvList.Rows) { if (((CheckBox)gvr.Cells[0].FindControl("cbSelect")).Checked) { gvList.DeleteRow(gvr.DataItemIndex); } } }
------解决方案--------------------
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="KHID" Width="100%" AllowPaging="True" PageSize="20" onpageindexchanging="GridView1_PageIndexChanging"> <Columns> <asp:TemplateField FooterText="全选" HeaderText="选择"> <HeaderTemplate> <asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True" OnCheckedChanged="CheckAll" Text="全选" /> </HeaderTemplate> <ItemTemplate> <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" Font-Names="宋体" Font-Size="9pt" /> </ItemTemplate>