GridView实现光棒及全选效果

来源:互联网 发布:百策早教管理软件 编辑:程序博客网 时间:2024/04/30 18:24

首先为gridView添加一个模板域,选择编辑模板,把复选框拖入到相应位置(布局--->位置--->未设置).

    <script type="text/javascript">
        function check(chk)
        {
            var items = document.getElementsByTagName("input");
            for(var i = 0; i < items.length; i++)
            {
                if(items[i].type == "checkbox")
                    items[i].checked = chk.checked;
            }
        }
    </script>

<asp:CheckBox ID="chkAll" onclick="check(this)" runat="server" Text="全选" />

光棒:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "currentColor=this.style.backgroundColor;this.style.backgroundColor='#E9E9DC'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentColor");
        }
    }

原创粉丝点击