mardi 3 janvier 2017

How to filter the select all checbox to select only spacific Column on a grid

I have a Select All checkbox Java Script which is selecting only enabled checkboxes on my Gridview. the issue is I have added another checkbox column to my grid and the current Java Script is selecting all enabled checkboxes for all columns.

Here is my ASP.NET code:

        <asp:templatefield>
        <itemtemplate>
            <asp:CheckBox ID="chkRowPaid"  runat="server" Enabled='<%# IIf((Convert.ToString(Eval("Amount_Paid_By_Driver"))) = "1", "false", "true")%>' />
        </itemtemplate>
        <headertemplate>
            <asp:CheckBox ID="SelectAllPaid" runat="server" onclick="CheckAllPaid(this);"   />
        </headertemplate>
        <headerstyle horizontalalign="left" />
        <itemstyle horizontalalign="left" />
    </asp:templatefield>

and the Java Script as below which prevents the disabled checkboxes to be checked:

    <script type="text/javascript" language="javascript">
    function SelectAll(objRef) {

        var GridView = objRef.parentNode.parentNode.parentNode;
        var inputList = GridView.getElementsByTagName("input");
        for (var i = 0; i < inputList.length; i++) {
            var row = inputList[i].parentNode.parentNode;


            if (objRef.checked && !inputList[i].disabled) {
                inputList[i].checked = true;
            }
            else {
                inputList[i].checked = false;
            }
        }
    }

</script>

Please update with Java Script only as I don't know how to use JQuery for the select all checkbox, also I am very week in Java Scripting.




Aucun commentaire:

Enregistrer un commentaire