girdview全选问题

在gridview外边不要放checkbox,不然当它取消选择时应该是什么功能就难以捉摸了。你可以放两个button,如下声明:

    <input type="button" value="全选" onclick="<%= Get全选脚本 %>" />
    <input type="button" value="反选" onclick="<%= Get反选脚本 %>" />

然后,页面的代码中实现这两个脚本(假设你的GridView的ID是GridView1,而每一行中要处理的CheckBox的ID是chb):


protected string Get反选脚本
    {
        get
        {
            string scp = "var ids=[";
            foreach (GridViewRow r in this.GridView1.Rows)
            {
                CheckBox ch = (CheckBox)r.FindControl("chb");
                if (ch != null)
                    scp += "'" + ch.ClientID + "',";
            }
            scp += "''];for(i=0;i<ids.length-1;i++) {var obj=document.getElementById(ids[i]);obj.checked=!obj.checked;};";
            return scp;
        }
    }

    protected string Get全选脚本
    {
        get
        {
            string scp = "var ids=[";
            foreach (GridViewRow r in this.GridView1.Rows)
            {
                CheckBox ch = (CheckBox)r.FindControl("chb");
                if (ch != null)
                    scp += "'" + ch.ClientID + "',";
            }
            scp += "''];for(i=0;i<ids.length-1;i++) {var obj=document.getElementById(ids[i]);obj.checked=true;};";
            return scp;
        }
    }

转自: http://topic.youkuaiyun.com/u/20081212/16/08BD398C-92BD-432D-99C4-3723B6E2035C.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值