zoukankan      html  css  js  c++  java
  • js 指定GridView全选,单选

    JS:

      
    //判定是单选还是全选
    var isMulti = "<% =Request.QueryString["mode"]%>"; //全选 function selectAll(ctlName, bool) { var ctl = document.getElementById(ctlName); var checkbox = ctl.getElementsByTagName('input'); for (var i = 0; i < checkbox.length; i++) { if (checkbox[i].type == 'checkbox') { checkbox[i].checked = bool; } } } var ClickNum=0;//判断同一checkbox连续点击次数 var PreCheckboxID="";//记录点击checkbox的ID //listId为控制checkbox的范围 //SelectRadio是点击checkbox自己 function SelectRadio(listId,SelectRadio) { if(isMulti == "") { ///判断是否连击同一个checkbox if(PreCheckboxID==SelectRadio.id) { ClickNumClickNum = ClickNum + 1; } else { PreCheckboxID = SelectRadio.id; ClickNum = 0; } //找到控制范围 var GridViewtableSearchList = document.getElementById(listId); //找到控制范围下所有input var objs = GridViewtableSearchList.getElementsByTagName("input"); //找到控制范围下所有checkbox并都变为false for(var i = 0; i < objs.length; i++) { if(objs[i].type.toLowerCase() == "checkbox" ) objs[i].checked = false; } var SelectRadioSelectRadioID = SelectRadio.id; //如果连击次数为奇次checked为true偶次为false if(ClickNum%2!=1) { document.getElementById(SelectRadioSelectRadioID).checked = true; } else { document.getElementById(SelectRadioSelectRadioID).checked = false; } } }

      

    html

     <asp:GridView ID="MainList" runat="server" AutoGenerateColumns="False" CssClass="DIVGrid"
                DataKeyNames="UG_ID" CellPadding="2" EmptyDataText="没有记录!" Width="520px" OnPageIndexChanging="MainList_PageIndexChanging">
                <Columns>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <asp:CheckBox runat="server" ID="cbHead" onclick="javascript:selectAll('MainList',this.checked);"
                                Text="选择"></asp:CheckBox>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:CheckBox runat="server" ID="cbItem"  onclick="javascript:SelectRadio('MainList',this);">
                            </asp:CheckBox>
                        </ItemTemplate>
                        <HeaderStyle HorizontalAlign="Center" Width="60px" />
                        <ItemStyle HorizontalAlign="Center" />
                    </asp:TemplateField>
                    <asp:BoundField DataField="UG_Name" HeaderText="部门">
                        <HeaderStyle HorizontalAlign="Center" Width="60" />
                    </asp:BoundField>
                </Columns>
            </asp:GridView>
  • 相关阅读:
    ValueError: source code string cannot contain null bytes
    django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 11001] No address found)")
    数据库索引
    Python深拷贝与浅拷贝
    ascii、unicode、utf-8、gbk
    map、reduce、filter 的用法
    TCP / UDP的区别
    男神鹏:SyntaxError: invalid character in identifier 报错!!
    男神鹏:机器学习之混淆矩阵的理解
    男神鹏:Visual Studio Code 解决红色波浪线操作
  • 原文地址:https://www.cnblogs.com/fuge/p/2766780.html
Copyright © 2011-2022 走看看