locked
on checking the child checkbox parent does not checked vise versa Works perfectly RRS feed

  • Question

  • User56316202 posted

    Hi I've these check boxes in

    asp.net repeater
    when I click the parent check box as you can see in this picture all child check boxes get check, in the other hand when I check the child check box the parent did not get selected. I'm using
    Jquery
    to achieve this My current
    ASP.NET
    code is as given below

    <ul id='<%# "p_"+Eval("ApplicationId") %>' class="child-ul-hide child-ul">
                                                        <asp:Repeater ID="rptrPages" runat="server" OnItemDataBound="rptrPages_ItemDataBound">
                                                            <ItemTemplate>
                                                                <li>
                                                             <%-- <span id='<%# "sp_"+Eval("PageId") %>' class="parent arrow-right" state="hide"></span>--%>
                                                                    <asp:Label ID="lblSpaces" runat="server" Text='<%# Eval("Spaces") %>'></asp:Label>
                                                                    <asp:Literal ID="ltrArrowSpan" runat="server"></asp:Literal>
                                                                    <label>
                                                                        <asp:CheckBox ID="chkPage" runat="server" Text='<%# Eval("PageTitle") %>'
                                                                            CssClass='<%# "page Pid_"+ Eval("ParentId")%>' PageId='<%# Eval("PageId") %>' ParentId='<%# Eval("ParentId") %>'
                                                                            Checked='<%# Eval("IsEnable")== null ? false: Convert.ToBoolean(Eval("IsEnable").ToString())  %>' />
                                                                    </label>
                                                                    <asp:HiddenField ID="hdPageId" runat="server" Value='<%# Eval("PageId") %>' />

    and my

    JavaScript
    code is as following as you can see I'd tried a couple of other stuff and used Intermediate snippiest too but when they are invited to
    ASP.NET
    Nothing goes as planed. many of you might suggest to use
    <input type='checkbox'/>
    sorry I can't do that

    $(document).ready(function () {
    
            /* Hide Show Tree lis
             *******************************************/
            $(".parent").click(function () {
    
                var ID = $(this).attr("id");
                var state = $("#" + ID).attr("state");
                if (state == "hide") {
    
                    $("#" + ID).attr('state', 'show');
                    $("#" + ID).addClass("arrow-down").removeClass("arrow-right");
                    ID = ID.replace("s", "");
                    $("#" + ID).addClass("child-ul-show").removeClass("child-ul-hide");
                }
                else {
    
                    $("#" + ID).attr('state', 'hide');
                    $("#" + ID).addClass("arrow-right").removeClass("arrow-down");
                    ID = ID.replace("s", "");
                    $("#" + ID).addClass("child-ul-hide").removeClass("child-ul-show");
                }
            });
    
        //    /* START Parent Enable CheckBox Click Event
        //   *********************************************/
            $(".page input[type='checkbox']").click(function() {
    
                var PageId = $(this).parent('.page').attr("PageId");
    
                var parentId = $(this).parent('.page').attr("ParentId");
    
                var EnableStatus = $(this).prop("checked");
    
                // Check/ Uncheck Controls Checkboxes
                $("." + PageId + " input[type='checkbox']").prop('checked', EnableStatus);
    
                //Check unCheck Childs Checkboxes
                $(".Pid_" + PageId + " input[type='checkbox']").prop('checked', EnableStatus);
    
    
                $(".Pid_" + PageId + " input[type='checkbox']").each(function() {
                    PageId = $(this).parent('.page').attr("PageId");
                    EnableStatus = $(this).prop("checked");
                    $(".Pid_" + PageId + " input[type='checkbox']").prop('checked', EnableStatus);
                });
    
                //$(".page input[type='checkbox']").prop('checked', false);
                //$(".Pid_" + ParentId + " input[type='checkbox']").each(function() {
                //    debugger;
                //    EnableStatus = $(this).prop("checked");
                //    if (EnableStatus) {
                //        $(".page input[type='checkbox']").prop('checked', EnableStatus);
                //        return false;
                //    }
                //});
                debugger;
                parentId = parseInt(parentId);
                if (parentId>0) {
                    $("input[type='checkbox'][ParentId^='" + parentId + "']").prop('checked', true);
    
                }
    
    
                /*/ */
                //$('input[name=' + parentId + '][value=Done][type=checkbox]:not(:checked)').attr({
                //    checked: 'checked',
                //    disabled: 'disabled'
                //});
    
    
    
            });

    Monday, December 21, 2015 6:11 AM

Answers