views:

114

answers:

1

I am trying to select all the check-boxes of the children in a Telerik RAD Tree view when the user checks a parent node and disable the check-boxes of all child nodes. I have a recursive function that is successfully checking the boxes, but i'm not having much luck in disabling all child check-boxes. Here is my code:

  <script type="text/javascript" language="JavaScript">
    function UpdateChildrenRecursively(nodes, checked)
    {
       var i;
       for (i=0; i<nodes.get_count(); i++)
       {
           if (checked)
           {
               nodes.getNode(i).check();     
           }
           else
           {
               nodes.getNode(i).set_checked(false);
           }

           // if the node has children, call the recursive function
           // then disable the checkboxes for each child
           if (nodes.getNode(i).get_nodes().get_count()> 0)
           {
               UpdateChildrenRecursively(nodes.getNode(i).get_nodes(), checked);
               nodes.getNode(i).get_nodes().disabled = true; 
           }
       }
    }
    function clientNodeChecked(sender, eventArgs)
    {
       var childNodes = eventArgs.get_node().get_nodes();
       var isChecked = eventArgs.get_node().get_checked();
       UpdateChildrenRecursively(childNodes, isChecked);
    }
</script>

Here's what the Telerik RAD Tree looks like:

<telerik:RadTreeView ID="RadTreeView2" OnClientNodeChecked="clientNodeChecked" CheckBoxes="true"
                    runat="server" DataSourceID="XmlDataSource1">
                    <DataBindings>
                        <telerik:RadTreeNodeBinding DataMember="Node" TextField="Text" ExpandedField="Expanded" />
                    </DataBindings>
                </telerik:RadTreeView>
                <asp:XmlDataSource runat="server" ID="XmlDataSource1" DataFile="Tree.xml" XPath="/Tree/Node" />
A: 

You should use nodes.getNode(i).set_enabled(false) to disable a node.

Milushev
Hmm, kinda works, but only disables each child node, not the siblings. And I did not account for the parent to be unchecked and its children/siblings to be re-enabled.
Neil