This is a migrated thread and some comments may be shown as answers.

unable to retrieve checked nodes in tree view

3 Answers 224 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Vinay
Top achievements
Rank 1
Vinay asked on 25 Nov 2010, 06:43 AM
Hi I have a tree view with checkboxes on each node. I have written some javascript to check relevant nodes when parent and child nodes on the tree view.

When i try to iterate through nodes on server side ie

foreach (RadTreeNode node in RadTree.CheckedNodes)
{
    string value = node.Text.ToString();
}

the value of CheckedNodes.Count = 0

Here is what I do with the javascript to check nodes
var node = args.get_node();
var parentnode = node.get_parent();
if (!node.get_checked()) {
    var childNodes = node._getChildren();
    var nodeArray = childNodes.toArray();
    for (var i = 0; i < nodeArray.length; i++) {
        nodeArray[i].set_checked(true);
        var GrandChildren = nodeArray[i]._getChildren();
        var nodeGCArray = GrandChildren.toArray();
        for (var x = 0; x < nodeGCArray.length; x++) {
            nodeGCArray[x].set_checked(true);
        }
    }

please help ..

3 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar Terziev
Telerik team
answered on 25 Nov 2010, 09:59 AM
Hello Vinay,

As i see you are using your private function to check all of the child items when a parent item is checked. My suggestion is to use the property CheckChildNodes, when set to true it will automatically check all child items.After that it shouldn't be a problem to get the count of the checked items on the server-side.


All the best,
Dimitar Terziev
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Vinay
Top achievements
Rank 1
answered on 25 Nov 2010, 11:09 PM
<td><telerik:RadTreeView ID="RadTree" runat="server" CheckBoxes="true" CheckChildNodes="true" OnClientNodeChecked="beforeClientCheck"></telerik:RadTreeView></td><td><td><telerik:RadTreeView ID="CloneRadTree" runat="server"></telerik:RadTreeView></td></td>

I have done this in the aspx page.

There does not seem to be a difference. Perhaps it would help to know that I am populating the Radtree using XML generated from a webservice. I do have a custom Attribute called Clone in node element.

I have also attached an image whilst debugging that shows the value of a few variables, such as checked state etc. Note  that checkable value in the node is True but the status is unchecked. Though I have checked it in the aspx page.
0
Vinay
Top achievements
Rank 1
answered on 26 Nov 2010, 01:11 AM
Sorry for wasting your time. It was because i did not check the IsPostBack == false on the Page_load method. Works fine ! My apologies.
Tags
TreeView
Asked by
Vinay
Top achievements
Rank 1
Answers by
Dimitar Terziev
Telerik team
Vinay
Top achievements
Rank 1
Share this question
or