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

Creating node not working

1 Answer 34 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Drew
Top achievements
Rank 1
Drew asked on 15 Jun 2012, 03:03 PM
I have created a RadTreeView in a web page.  it is displaying and working properly.  However, I am trying to create a node and add it to the TreeView using the example found at http://demos.telerik.com/aspnet-ajax/treeview/examples/programming/clientsideapi/defaultcs.aspx.  When I do that, it is failing.  The code I am using is:

function addNode() {
        treeView.trackChanges();
        var node = new Telerik.Web.UI.RadTreeNode();
        node.set_text(FeatureNameText.get_value());
        var parent = treeView.get_selectedNode() || treeView;
        parent.get_nodes().add(node);
        if (parent != treeView && !parent.get_expanded())
            parent.set_expanded(true);
        treeView.commitChanges();
        return false;
    }

When stepping through the above code, it gets to the node.set_text and throws an exception that says node is null or not an object.  What am I doing wrong here?

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Jun 2012, 05:42 AM
Hi Drew,

Here is the code snippet that worked as expected.

ASPX:
<telerik:RadTreeView ID="RadTreeView1" runat="server" CheckBoxes="true">
  <Nodes>
     <telerik:RadTreeNode Text="RadTreeNode1">
     </telerik:RadTreeNode>
     <telerik:RadTreeNode Text="RadTreeNode2">
     </telerik:RadTreeNode>
     <telerik:RadTreeNode Text="RadTreeNode3">
     </telerik:RadTreeNode>
  </Nodes>
</telerik:RadTreeView>
<telerik:RadTextBox ID="RadTextBox1" runat="server">
</telerik:RadTextBox>
<asp:Button ID="Button1" runat="server" OnClientClick="OnClientClick(); return false;" />

JS:
<script type="text/javascript">
    function OnClientClick() {
        var treeView = $find("<%= RadTreeView1.ClientID %>");
        var FeatureNameText = $find("<%= RadTextBox1.ClientID %>");
        treeView.trackChanges();
        var node = new Telerik.Web.UI.RadTreeNode();
        node.set_text(FeatureNameText.get_value());
        var parent = treeView.get_selectedNode() || treeView;
        parent.get_nodes().add(node);
        if (parent != treeView && !parent.get_expanded())
            parent.set_expanded(true);
        treeView.commitChanges();
        return false;
    }
</script>

Please provide your full code if it doesn't help.

Thanks,
Princy.
Tags
TreeView
Asked by
Drew
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or