Auto-select child checkboxes
<p>I've to work with the roles of the users, that I have in a sql base. 
Every role has a checkbox, the idea is to check the "childrens" checkboxes if the "parent" is checked, and check the "parent" if all the "childrens" are checked.</p>

<p>I tried this script in a page and it worked, but I can not make this work in my asp.net </p>

<p>This is my script and code.</p>

<pre class="lang-js prettyprint-override"><code>$(document).ready(function () {
    $('.parent').click(function () {
        if ($(this).is(':checked'))
            $(this).parent().find('.children input[type="checkbox"]').attr('checked', 'checked');
    });

    $('.children input[type="checkbox"]').click(function () {
        var numberOfCheckboxes = $(this).parents('.children').find('input[type="checkbox"]').length;

        if ($(this).parents('.children').find('input[type="checkbox"]').filter('input[checked=checked]').length == numberOfCheckboxes)
            $(this).parents('div').find('.parent').attr('checked', 'checked');
    });
});
</code></pre>

<pre class="lang-html prettyprint-override"><code>&lt;div&gt;
    &lt;asp:DataList ID="outerDataList" runat="server" DataSourceID="ObjectDataSource2" &gt;
        &lt;ItemTemplate&gt;
            &lt;li&gt;
                &lt;asp:Label ID="idLabel" runat="server" Text='&lt;%# Eval("id") %&gt;'
                    Visible="False" /&gt;
                &lt;asp:Label ID="typeLabel" runat="server" Text='&lt;%# Eval("type") %&gt;'
                    Visible="False" /&gt;
                &lt;asp:CheckBox ID="chkEnabled" class="parent" runat="server"
                    Checked='&lt;%# Eval("Enabled") %&gt;' Text='&lt;%# Eval("name") %&gt;' /&gt;
            &lt;/li&gt;
            &lt;ul class="children"&gt;
                &lt;asp:DataList ID="innerDataList" runat="server" DataSource='&lt;%# Eval("Roles") %&gt;'&gt;
                    &lt;ItemTemplate&gt;                                
                        &lt;li&gt;
                            &lt;asp:Label ID="idLabelInt" runat="server"
                                Text='&lt;%# Eval("id") %&gt;' Visible="False" /&gt;
                            &lt;asp:Label ID="typeLabelInt" runat="server"
                                Text='&lt;%# Eval("type") %&gt;' Visible="False" /&gt;
                            &lt;asp:CheckBox ID="chkEnabledInt" runat="server"
                                Checked='&lt;%# Eval("Enabled") %&gt;' Text='&lt;%# Eval("name") %&gt;' /&gt;
                        &lt;/li&gt;
                    &lt;/ItemTemplate&gt;
                &lt;/asp:DataList&gt; 
            &lt;/ul&gt;                   
        &lt;/ItemTemplate&gt;
    &lt;/asp:DataList&gt;
&lt;/div&gt;
</code></pre>
