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);
    }
  • 相关阅读:
    JSTLView快速国际化(SpringMVC)
    SprngMVC源码学习
    请求数据传入(SpringMVC)
    @ModelAttribute注解(SpringMVC)
    SpringMVC-RESTRUL___CRUD知识点总结
    SpringMVC视图解析器概述
    Spring
    英文单词
    关于陌生的依赖模块,如withStyles、react-apollo等
    React项目中那些奇怪的写法
  • 原文地址:https://www.cnblogs.com/wonder315/p/1938410.html
Copyright © 2011-2022 走看看