Home - Forums-.NET - FlyTreeView (ASP.NET) - Problems updating node.Text in the FlyTree

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

Problems updating node.Text in the FlyTree
Link Posted: 08-Nov-2007 15:35
Hi.

Im having problems updating the Text-attribute of a TreeNode in the TreeView. As far as I understand it node.Text doesnt work at all. To set the node text when populating the Flytree I do this:


FlyTreeNode node = new FlyTreeNode();
node.NodeTypeID = nodeTypeID;
node.Attributes.Add( \"Name\", nodeName );
node.Value = Convert.ToString( nodeValue );
node.ToolTip = nodeTooltip;

if (nodeChilds > 0)
{
  FlyTreeNode dummyNode = new FlyTreeNode();
  dummyNode.Text = \"Loading...\";
  node.ChildNodes.Add( dummyNode );
  node.PopulateNodesOnDemand = true;
}
else
  node.PopulateNodesOnDemand = false;
node.Expanded = false;


which matches the following declaration in the aspx-page:



  
    '>
  
  .....


This works great and when I do an update on the text for a \"top\"-node this also works great:


FlyTreeNode selectedNode = FlyTreeView.SelectedNode;
int selectedNodeIndex = selectedNode.Index;
int selectedNodeChildrens = selectedNode.ChildNodes.Count;
FlyTreeView.Nodes.Remove( selectedNode );

FlyTreeNode node = new FlyTreeNode();
node.NodeTypeID = nodeTypeID;
node.Attributes.Add( \"Name\", nodeName );

node.Value = Convert.ToString( nodeValue );
if (selectedNodeChildrens > 0)
{
  FlyTreeNode dummyNode = new FlyTreeNode();
  dummyNode.Text = \"Loading...\";
  node.ChildNodes.Add( dummyNode );
}
node.Expanded = false;
FlyTreeView.Nodes.Insert( selectedNodeIndex, node );


But that will not work for nodes one level down or more. So I wrote this (see code below) which in my mind should work, but then I get an error when the page renders - not in my code. So what am I doing wrong? And is this really the correct way to update the node.Text?
Here is the code that doesnt work (its similar to the one above that works except for finding Parent node and using Parent.ChildNodes instead of FlyTreeView.Nodes to remove the old node and adding the new:


int selectedNodeIndex = FlyTreeView.SelectedNode.Index;
int selectedNodeChildrens = FlyTreeView.SelectedNode.ChildNodes.Count;
FlyTreeNode parentNode = FlyTreeView.SelectedNode.Parent;
parentNode.Selected = true;
parentNode.ChildNodes.Remove( FlyTreeView.SelectedNode );

FlyTreeNode node = new FlyTreeNode();
node.NodeTypeID = nodeTypeID;
node.Attributes.Add( \"Name\", nodeName );

node.Value = Convert.ToString( nodeValue );
if (selectedNodeChildrens > 0)
{
  FlyTreeNode dummyNode = new FlyTreeNode();
  dummyNode.Text = \"Loading...\";
  node.ChildNodes.Add( dummyNode );
}
node.Expanded = false;
parentNode.ChildNodes.Insert( selectedNodeIndex, node );




I realize this isnt easy to grasp without having the entire code but its integrated into something bigger and much more complicated so that wont help. Maybe I can get some help anyway.

Any help is very much appreciated!

regards
Henrik
Link Posted: 08-Nov-2007 15:41
...

MESSAGE:
Object reference not set to an instance of an object.

STACKTRACE:
   at NineRays.WebControls.FlyTreeNode.get_NodeType()
   at NineRays.WebControls.FlyTreeNode.SetContentContainer(Boolean useDataBinding, Boolean useDataBindingSoft)
   at NineRays.WebControls.FlyTreeNode.DataBindContentContainerRecursive()
   at NineRays.WebControls.FlyTreeView.SetContentContainersRecursive()
   at NineRays.WebControls.FlyTreeView.OnPreRender(EventArgs e)
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Link Posted: 08-Nov-2007 22:31
Henrik,

Why are you using ContentTemplate, and not just set
node.Text = \"yourvalue\"

?

ContentTemplate is not required to make treeview show its node.Text.
It is a replacement for node.Text, that allows server-side templates to be used instead of plain node.Text value.

From my point of view, you should just remove ContentTemplate declaration from the node type and use simple node.Text = nodeName instead.