Saturday, 27 September 2014

validate atleast on selection inside gridview using javascript




//Gridview

<asp:TemplateField >
 <ItemTemplate>
 <asp:CheckBox runat="server" ID="Chk_allCh" />
  </ItemTemplate>
 <HeaderTemplate>
 <asp:CheckBox runat="server" ID="Chk_all" onclick="checkAllRow(this);" />
</HeaderTemplate>

</asp:TemplateField>


//Script
function checkvalidateSelect() {
        var gridView = document.getElementById('<%=GridViewID.ClientID %>');
                    
                    var isValid = false;

                    for (var i = 1; i < gridView.rows.length; i++) {
                        var inputs = gridView.rows[i].getElementsByTagName('input');
                        if (inputs != null) {
                            if (inputs[0].type == "checkbox") {
                                if (inputs[0].checked) {
                                    isValid = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (!isValid) {
                 alert('Please select at least one');
                        return false;
                    }
                    else
                    { return true; }

                }         

No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...