Friday, June 10, 2016

Allow One CheckBox only in GRIDVIEW

Allow Once CheckBox only in GRIDVIEW

'--allow one checkbox only in GRIDVIEW
<script type="text/javascript" lang="javascript">
    function CheckOne(obj) {
        var grid = obj.parentNode.parentNode.parentNode;
        var inputs = grid.getElementsByTagName("input");
        for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].type == "checkbox") {
                if (obj.checked && inputs[i] != obj && inputs[i].checked) {
                    inputs[i].checked = false;
                }
            }
        }
    }
</script>



'--inside your gridview
<asp:TemplateField HeaderText="Pilih">
                        <ItemTemplate>
                            <asp:CheckBox ID="chkSelect" runat="server" onclick="CheckOne(this)" />
                        </ItemTemplate>
</asp:TemplateField>