Gridview复选框条件检查未选中 [英] Gridview check box condition check uncheck

查看:77
本文介绍了Gridview复选框条件检查未选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有复选框列的GridView.我要顺序地取消选中这些复选框,即,如果前一行未选中,则无法检查一行.同样,如果未选中该行,则其旁边的所有行都将处于未选中状态.使用JavaScript ..


等待回复.
在此先感谢

I Have a GridView having a check box column.I want to check uncheck these check boxes serially i.e.a row can not be checked if its previous row is unchecked..similarly if a row is unchecked all rows next to it will be unchecked using JavaScript..


Waiting for Reply.
Thanks in Advance

推荐答案

选中GridView中的所有复选框以批量编辑或更新ASP.NET [使用客户端脚本和所有复选框选中GridView中的所有复选框 [
Check All Checkbox In GridView To Bulk Edit Or Update ASP.NET[^] should help you out.

Checking All CheckBoxes in a GridView Using Client-Side Script and a Check All CheckBox[^] could be useful to you as well.


使用JavaScript,找到网格的对象并找到网格的row.count.
使用for循环启用或禁用网格的复选框,并与选择索引进行比较.
using javascript, find object of grid and find rows.count of grid.
using for loop enable or disable check boxes of grid with using comparision with selecting index.


您可以尝试一下,

You can try this,

<asp:GridView ID="gvBranches" runat="server" AutoGenerateColumns="False" CellPadding="4"

        Font-Names="Verdana" Font-Size="11px" GridLines="None"

        Width="182px">
        <Columns>
            <asp:TemplateField HeaderText="Check_All">
                <HeaderTemplate>
                    <asp:CheckBox ID="CheckBox2" runat="server" onclick="checkAll(this);" />
                </HeaderTemplate>
                <ItemStyle HorizontalAlign="Left" Width="30px" />
                <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" />
                <ItemTemplate>
                    <asp:CheckBox ID="CheckBox3" runat="server" onclick="Check_Click(this)" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Column">
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text="Some Value"></asp:Label>
                </ItemTemplate>
                <HeaderStyle HorizontalAlign="Left" />
            </asp:TemplateField>
        </Columns>
    </asp:GridView>




js函数就像,




And js functions are like,

<script type="text/javascript">
        function checkAll(objRef) {
            var GridView = objRef.parentNode.parentNode.parentNode;
            var inputList = GridView.getElementsByTagName("input");
            var c = 0;
            for (var i = 0; i < inputList.length; i++) {
                var row = inputList[i].parentNode.parentNode;
                if (inputList[i].type == "checkbox" && objRef != inputList[i]) {
                    if (objRef.checked) {
                        c = 1;
                        inputList[i].checked = true;
                    }
                    else {
                        c = 0;
                        inputList[i].checked = false;
                    }
                }
            }

        }
        function Check_Click(objRef) {
            var row = objRef.parentNode.parentNode;
            var GridView = row.parentNode;
            var inputList = GridView.getElementsByTagName("input");
            var c = 0;
            inputList[0].checked = true;
            for (var i = 1; i < inputList.length; i++) {
                if (inputList[i].type == "checkbox" && inputList[i].checked == true) {
                    c = 1;
                }
                else {
                    inputList[0].checked = false;
                }
            }

        }
    </script>


这篇关于Gridview复选框条件检查未选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆