Thursday, August 11, 2011

Disabling/Enabling asp.net checkboxlist items using javascript

Posted by Rahul Kharde at 3:13 AM

The ASP.NET Checkboxlist control provides a way for you to add checkboxes as listitems.

While this control makes working with multiple checkboxes much easier it lacks one very key item, an enable property. The only workaround for this at the moment is to add a javascript function which does the enabling and disabling automatically.

Below is javascript that will enable or disable on listitems(Checkbox 5) on listitems (Checkbox 1)


Javascript



        function EnableDisableCheckbox() {
            var chkList2 = document.getElementById('<%=CheckBoxList1.ClientID %>');
            var checkbox2 = chkList2.getElementsByTagName("input");

            if (checkbox2[0].checked) {
                checkbox2[1].disabled = false;
            }
            else {
                checkbox2[1].disabled = true;
            }
        }

HTML
 
<asp:CheckBoxList ID="CheckBoxList1" runat="server" Width="109px">
    <asp:ListItem Value="1">Check Box 1</asp:ListItem>
    <asp:ListItem Value="2">Check Box 2</asp:ListItem>
    <asp:ListItem Value="3">Check Box 3</asp:ListItem>
    <asp:ListItem Value="4">Check Box 4</asp:ListItem>
    <asp:ListItem Value="5">Check Box 5</asp:ListItem>
    <asp:ListItem Value="6">Check Box 6</asp:ListItem>
    <asp:ListItem Value="7">Check Box 7</asp:ListItem>
    <asp:ListItem Value="8">Check Box 8</asp:ListItem>
</asp:CheckBoxList>





If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you subscribe to my regular Email Updates. Subscribe Now!


Kindly Bookmark and Share it:

YOUR ADSENSE CODE GOES HERE

1 comments:

Ratan Pandey on December 11, 2016 at 11:58 AM said...

its not working


Have any question? Feel Free To Post Below:

 

Popular Posts

Recent Comments

© 2011. All Rights Reserved | Help to understand .Net | Template by Blogger Widgets

Home | About | Top