Skip to content Skip to sidebar Skip to footer

Asp.net Enable/disable Checkboxlist With Jquery

I have this kind of structure: Radio Buttons: o Enable o Disable Check Boxes []checkBox1 []checkBox2 []checkBox3 []checkBox4 The Above controls are generated dynamically.

Solution 1:

Try something like this:

$("#cblSubsidiaries > input[type='checkbox']").prop("disabled", false)

Update:

$("#contentpage_0_content_0_cblSubsidiaries input[type=checkbox]").prop("disabled",false)

Solution 2:

This is the code which will help you

Html

<inputtype="radio" name="check" value="enable" class="enableList">Enable
    <inputtype="radio" name="check" value="disable" class="disableList">Disable    

<div class="container">
 <inputtype="checkbox" name="vehicle" value="Bike">I have a bike<br>
 <inputtype="checkbox" name="vehicle" value="Car">I have a car </div>

Script

$(document).ready(function () {           
        $('.enableList').change(function () {
            if ($(this).prop('checked') == true) {
                $('.container').find('input:checkbox').each(function () {
                    alert ("enable check box");
                });
            }
        });


        $('.disableList').change(function () {
            if ($(this).prop('checked') == true) {
                $('.container').find('input:checkbox').each(function () {
                    alert("disable check box");
                });
            }
        });

    });

this is working fidler https://jsfiddle.net/Ln7y6v0n/

Solution 3:

Something like this should work:

$('#contentpage_0_content_0_cblSubsidiaries input[type=checkbox]').each(function() {
      $(this).prop('checked', true);
 });

Solution 4:

 $(document).ready(function () {

            $('#<%=RadioButtonList1.ClientID%>').change(function () {
                 $('#<%=RadioButtonList1.ClientID%>').each(function () {
                     var checked = $(this).find('input:radio:checked');
                     if (checked.val() == "Enable") {

                         $('#<%=CheckBoxList1.ClientID%>').each(function () {
                             var checked = $(this).find('input:checkbox');
                             checked.prop('checked', true);
                         });
                     }
                     else {

                         $('#<%=CheckBoxList1.ClientID%>').each(function () {
                             var checked = $(this).find('input:checkbox');
                             checked.prop('checked', false);
                         });
                     }
                 });
             });
        });

 protected voidPage_Load(object sender, EventArgs e)
        {
            ListItem item = newListItem();
            item.Text = "Enable";
            item.Value = "Enable";
            RadioButtonList1.Items.Add(item);

            ListItem item1 = newListItem();
            item1.Text = "Disable";
            item1.Value = "Disable";
            RadioButtonList1.Items.Add(item1);

            for (int i = 1; i <= 4; i++)
            {
                ListItem chkitem = newListItem();
                chkitem.Text = "Checkbox" + i;
                chkitem.Value = "Checkbox" + i;
                CheckBoxList1.Items.Add(chkitem);
            }

        }

<div><asp:RadioButtonListID="RadioButtonList1"runat="server"></asp:RadioButtonList><br /><hr /><asp:CheckBoxListID="CheckBoxList1"runat="server"></asp:CheckBoxList></div>

Post a Comment for "Asp.net Enable/disable Checkboxlist With Jquery"