黑马程序员_全选反选

全选反选功能的实现
前台:
全选:<asp:CheckBox ID="chSelectAll" runat="server" OnCheckedChanged="chSelectAll_CheckedChanged"
                AutoPostBack="true" />&nbsp&nbsp
反选:<asp:CheckBox ID="chSelectOtherAll" runat="server"
                    OnCheckedChanged="chSelectOtherAll_CheckedChanged" AutoPostBack="true" />&nbsp&nbsp

后台:
        /// <summary>
        /// 全选
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void chSelectAll_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < this.grdList.Rows.Count; i++)
            {
                CheckBox cbox = (CheckBox)grdList.Rows[i].FindControl("ckbSelect");
                //cbox.Checked = chSelectAll.Checked;
                cbox.Checked = true;
            }
        }

        /// <summary>
        /// 反选
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void chSelectOtherAll_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < this.grdList.Rows.Count; i++)
            {
                CheckBox cbox = (CheckBox)grdList.Rows[i].FindControl("ckbSelect");
                cbox.Checked = !cbox.Checked;
            }
        }

 

 

posted @ 2013-04-16 19:17  微笑的小鸟  阅读(120)  评论(0编辑  收藏  举报