Thursday 19 February 2015

Select De-Select all nodes of the Treeview in asp.net using jquery




//html

<asp:TreeView ID="TreeView1" ShowCheckBoxes="All" runat="server" NodeIndent="15"   >
                            <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
                            <NodeStyle Font-Names="Arial" Font-Size="9pt" ForeColor="Black" HorizontalPadding="1px"
                                NodeSpacing="0px" VerticalPadding="1px" ></NodeStyle>
                            <ParentNodeStyle Font-Bold="False" />

                        </asp:TreeView>

<script>

Sys.Application.add_load(jScript);
                function jScript() {
                    $("[id*=TreeView1] input[type=checkbox]").bind("click", function () {
                        var table = $(this).closest("table");
                        if (table.next().length > 0 && table.next()[0].tagName == "DIV") {
                            //Is Parent CheckBox
                            var childDiv = table.next();
                            var isChecked = $(this).is(":checked");
                            $("input[type=checkbox]", childDiv).each(function () {
                                if (isChecked) {
                                    $(this).attr("checked", "checked");
                                } else {
                                    $(this).removeAttr("checked");
                                }
                            });
                        } else {
                            //Is Child CheckBox
                            var parentDIV = $(this).closest("DIV");
                            if ($("input[type=checkbox]", parentDIV).length == $("input[type=checkbox]:checked", parentDIV).length) {
                                $("input[type=checkbox]", parentDIV.prev()).attr("checked", "checked");
                            } else {
                                $("input[type=checkbox]", parentDIV.prev()).removeAttr("checked");
                            }
                        }
                    });

                }
</script>

//result


No comments:

Post a Comment

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...