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

Loading New Nodes From Database

2 Answers 126 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
tbrown
Top achievements
Rank 1
tbrown asked on 25 Jun 2008, 07:16 AM

Hi all,

I have a tree view that is going to be used for an email application and has all of its folder structure bound from a self referencing database table. When I do my binding I set a node attribute of FolderId to each node on the NodeDataBound event (e.Node.Attributes.Add("FolderId", currentNode["FolderId"].ToString());) so that I can access the FolderId in the code behind.

I have a context menu on the tree view that allows the user to add, rename and delete a folder. This is done on the ContextMenuItemClick event of the context menu and updates the database accordingly. Howerver what I am having problems with is updating the new folder with the new default text of ‘New Folder’ and applying the newly created FolderId from the database when a user clicks the create item in the context menu. The only way I found to do this is to reload the whole menu in again and bind. However this is a very poor solution and with the possability of hundereds of folders performance is likely to suffer and has the addeded annoyence of closing the menu back to the root rather than keeping it open on the selected node.

Is there a way I can click the context menu and create the new folder by adding it to the database. Then updating the newly created folder with its FolderId from the database whilst keeping the menu expanded on the selected node?

Any help with this would be much appreciated.

2 Answers, 1 is accepted

Sort by
0
Sergej
Top achievements
Rank 1
answered on 29 Sep 2009, 05:50 PM

I have similar problem when adding new node from code behind. Problem is related to binding data to treeview, My node template looks like this:

[<%# DataBinder.Eval(Container, "Value")%>] <%# DataBinder.Eval(Container, "Text")%>

from codebehind node is added :

RadTreeNode newNode = new RadTreeNode("MyNewNode", "2222");

rtv1.Nodes.Add(newNode);

In tree new node looks like this: "[] ".  I know the node is added because if i edit (rename) the node from client side "[] " it will show MyNewNode text in textbox so I can edit the text.

I have latest official release of rad controls.

Support please tell us what to do.

0
Yana
Telerik team
answered on 02 Oct 2009, 10:54 AM
Hi Sergej,

You should also call DataBind method of the node:

RadTreeNode newNode = new RadTreeNode("MyNewNode""2222"); 
rtv1.Nodes.Add(newNode); 
newNode.DataBind(); 

Kind regards,
Yana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
TreeView
Asked by
tbrown
Top achievements
Rank 1
Answers by
Sergej
Top achievements
Rank 1
Yana
Telerik team
Share this question
or