Saturday, 15 July 2017

Custom Validator for Checkbox inside gridview checked or not

Alert using Custom Validator for Checkbox inside gridview checked or not 

 <script type="text/javascript">  
function Validate(sender, args) {
            var gridView = document.getElementById("<%=grid_ECL.ClientID %>");
            var checkBoxes = gridView.getElementsByTagName("input");
            for (var i = 0; i < checkBoxes.length; i++) {
                if (checkBoxes[i].type == "checkbox" && checkBoxes[i].checked) {
                    args.IsValid = true;
                    return;
                }
            }
            args.IsValid = false;
        }          
   </script>
========================================================================
   <asp:CustomValidator ID="CustomValidator1" runat="server" ValidationGroup="print" ErrorMessage="Please select at least one record." ClientValidationFunction="Validate" ForeColor="Red"></asp:CustomValidator>

========================================================================

 <asp:Button ID="btnA4" runat="server" Text="Print A4" OnClick="btnA4_Click" ValidationGroup="print" />

No comments:

Post a Comment