关于CheckBox 控件的一些操作

checkBox 的全选效果
<script type="text/javascript">
    function GetAllCheckBox(CheckAll)
    {
        var items = document.getElementsByTagName("input");
        for (i = 0; i < items.length; i++)
        {
            if (items[i].type == "checkbox")
            {
                items[i].checked = CheckAll.checked;
            }
        }
    }
</script>
给checkbox 添加onclick事件
οnclick="GetAllCheckBox(this)"

是否删除选中的数据行Button 的 delete 事件
<script type="text/javascript">
 function delte() {
        var items = document.getElementsByTagName("input");
        for (i = 0; i < items.length; i++) {
            if (items[i].type == "checkbox") {
                if (items[i].checked == true)
                {
                    return confirm('确认要删除选中的数据吗??');
                } else {
                    alert('请选择要删除的数据!');
                    return false;
                }
            }
        }
       
    }
</script>
给Button 按钮添加 OnClientClick 事件

后台删除方法
Button 的删除事件
        protected void ibtnDelete_Click(object sender, ImageClickEventArgs e)
        {       
            string list = "";          
            foreach (RepeaterItem rpt in this.rptXXGLList.Items)
            {
                CheckBox cb=rpt.FindControl("checkBox") as CheckBox;
                if (cb.Checked)
                {
                    HiddenField hf = rpt.FindControl("hiddFid") as HiddenField;//主键值
                    int id = Convert.ToInt32(hf.Value);
                    list += id + ",";
                }
            }
            string listAll = list + " ";
            if (JF_ShowsManager.DeleteList(listAll))
            {
                Common.Alert(this, "删除成功!");
                SearchInfos();
            }
            else
            {
                Common.Alert(this, "删除失败!");
                return;
            }
        }

 

后台代码

 

 //删除选中的所有数据
        protected void btndel_Click(object sender, EventArgs e)
        {
            CheckBox chk;
            string id = "(0";
            foreach (RepeaterItem Ri in rptE_Comp.Items)
            {
                chk = (CheckBox)Ri.FindControl("ckbcheck");
                if (chk.Checked)
                {
                    HiddenField i = Ri.FindControl("hf") as HiddenField;
                    id = id + "," + i.Value.ToString();
                }
            }
            id = id + ")";
            if (E_companyManager.Delete(id))
            {
                BintRpt(this.AspNetPager1.CurrentPageIndex);
            }
            else
            {
                MessageBox.Alert(this,"删除失败!");
                return;
            }
          
        }
        //选中所有数据
        protected void chkAll_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < rptE_Comp.Items.Count; i++)
            {
                CheckBox chk = (CheckBox)rptE_Comp.Items[i].FindControl("ckbcheck");
                if (chkAll.Checked)
                {
                    chk.Checked = true;
                }
                else
                {
                    chk.Checked = false;
                }
            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值