GridView技巧4:为GridView加入全选


 <asp:TemplateField HeaderText="全选">
        <HeaderTemplate>
                <asp:CheckBox ID="checkall" runat="server" Text="全选" 
                        AutoPostBack="true" OnCheckedChanged="checkAll" />
         </HeaderTemplate>
          <ItemTemplate>
                   <asp:CheckBox ID="check" runat="server" Text="选择" />
            </ItemTemplate>     
</asp:TemplateField>

   protected void checkAll(object sender, EventArgs e)
  {
       CheckBox cb = (CheckBox) sender;
       if (cb.Text == "全选")
       {
           foreach (GridViewRow gvr in gvLessons.Rows)
           {
               CheckBox cb1 = (CheckBox)gvr.FindControl("check");
               cb1.Checked = cb.Checked;
           }
       }
    }
注:参考天轰穿的DataGrid系列技巧(导出excel,事件,多种方式呈现数据,全选全删)等等等
在此感谢天轰穿
posted on 2006-10-13 15:13  灵风  阅读(441)  评论(0编辑  收藏  举报