zoukankan      html  css  js  c++  java
  • 【Wonder原创】GridView—CheckBox全选

    一、前台

    代码
    <asp:TemplateField>
    <HeaderTemplate>
    <asp:CheckBox ID="chkALL" runat="server" Text="全选" AutoPostBack="false" />
    </HeaderTemplate>
    <ItemTemplate>
    <asp:CheckBox ID="ck_Select" runat="server" Width="20px" />
    <asp:Label ID="D_lrrr" runat="server" Font-Bold="true" ForeColor="Red" Text='<%# (Container.DataItemIndex+1)+"." %>'
    Visible="true" Width="20px">
    </asp:Label>
    </ItemTemplate>
    <ItemStyle HorizontalAlign="Left" Width="50px" />
    javascript
    <script language="javascript" type="text/javascript">
    function selectAll(ctlName,headchkid)
    {
    var chkall = document.getElementById(headchkid);
    var bool = chkall.checked ;
    var ctl = document.getElementById(ctlName);//根据控件的在客户端所呈现的ID获取控件
    var checkbox = ctl.getElementsByTagName('input');//获取该控件内标签为input的控件
    /*所有Button、TextBox、CheckBox、RadioButton类型的服务器端控件在解释成Html控件后,都为<input type=''./>,通过type区分它们的类型。*/
    for(var i=0;i<checkbox.length;i++)
    {
    if(checkbox[i].type=='checkbox')
    {
    checkbox[i].checked
    = bool ;
    }
    }
    }
    </script>

    二、后台

    RowDataBound
    if (e.Row.RowType == DataControlRowType.Header)
    {
    CheckBox chk
    = (CheckBox)e.Row.FindControl("chkALL");
    string str = string.Format("javascript:selectAll('{0}','{1}');",gvList.ClientID,chk.ClientID);
    chk.Attributes.Add(
    "onclick", str);
    }
  • 相关阅读:
    mysql用户密码修改
    Java List java.lang.UnsupportedOperationException
    python __dict__
    pytest.fixture
    Python __metaclass__ 解释
    Python __new__()方法,为对象分配内存 返回对象的引用
    git 常用操作
    boto3 dynamodb 一些简单操作
    conda, pip, virtualenv 区别
    list去重后不改变排序
  • 原文地址:https://www.cnblogs.com/wonder315/p/1938410.html
Copyright © 2011-2022 走看看