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

Store a Node or a Tree in a File or Database

4 Answers 106 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Christian Sommer
Top achievements
Rank 1
Christian Sommer asked on 26 Nov 2009, 12:31 AM
Hello,

sometime I'm creating trees based on  very complex and timeconsumpting database-queries.

My question is, if it is possible to store the  tree (after first creation in a file or database,
so it can be cached for other users.

Second question is: how to set the tree from that cache (usually a binary-text)?

Is there an easy way to do that?

Best regards.

4 Answers, 1 is accepted

Sort by
0
Roland
Top achievements
Rank 1
answered on 26 Nov 2009, 01:59 AM
Hello,

RadTreeView does not have this functionality, however this is easy to achieve.

The tree supports binding to hierarchical data Binding to Hierarchical data. Given this, you would prepare a table:

MySavedNodesTable:
- TreeId //to support multiple different trees in the same table
- Id
- ParentId
- NodeText
- NodeValue

The table would have the data that comes from your complex queries.

Then you would only query this table given the TreeId and bind the data to the tree with the following settings:
var list = new List<MySavedNodeObject>()
//add nodes from database to the list

 treeView.DataTextField = "NodeText";
treeView.DataValueField = "NodeValue";
treeView.DataFieldID = "Id";
treeView.DataFieldParentID = "ParentId";
treeView.DataSource = list;
treeView.DataBind();

Please refere to the link above how to achieve the required functionality.

0
Accepted
Peter
Telerik team
answered on 26 Nov 2009, 03:37 PM
Hi Christian,

You can also consider using the GetXml() and LoadXmlString() methods of RadTreeView.

http://www.telerik.com/help/aspnet-ajax/tree_serverhowtocloning.html


All the best,
Peter
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.
0
Christian Sommer
Top achievements
Rank 1
answered on 27 Nov 2009, 12:57 AM
Hello Roland,

Unfortunately I'm not able to create a simple structured table an then uns a web-service for dynamic load node per node,
level by level.

In my application very much is customizeable, (different styles, different contextmenus, some nodes are checkable, some are not, etc.)

So, at the end of developing, It could be that I'll try to create a webservice which returns nodes - not node-data.
... and I'll attach it to the tree, by manipulationg the innerHTML.
Well, in fact, we're just starting to develop with telerik tools, we'd like to youse default features more then to create our own work-arrounds.

________________________________________________________________________________________

But Roland,
your tip is not obsolete, because I could save the time consupting query results in a temp-table wich could be accessed much faster.

First I'll try GetXml() and LoadXmlString() .

Thanks a lot.

Christian
0
Christian Sommer
Top achievements
Rank 1
answered on 10 Dec 2009, 11:32 AM
Hello,

I've experienced some tests with the
GetXml() and LoadXmlString() methods.

They're working great, when you're able to store a complete tree.

Now I need a little bit mor help:
To improve cachinng, I want to cache my TreeRootNodes, which are created with theire own definitions.
Differen users could see different RootNodes, so I can't cache the entire tree.

In fact, TreeNodes don't have a GetXml() method, I've experienced with a litle work a round.
I've create a second Treeview called "CacheTree". After creating so RootNode (with all its Subnodes)
I'm storing this Node by its own in the CacheTree and store its XML with the GetXml() method.

My problem now is to restore that XML back to the RootNode Object.

1. Caching
CacheTree.Nodes.Add(RootNode)

...

rsCaching.Fields(

"CachingTime").Value = Now

 

 

rsCaching.Fields(

"CachedTree").Value = CacheTree.GetXml()

 

 

 

2. Load Cached Value
CacheTree.Nodes.Clear()

 

 

CacheTree.LoadXmlString(rsCaching.Fields("CachedTree").Value)
---- Here's my Problem ----

 

 

MasterNode = CacheTree.GetAllNodes
Now MasterNode contains only the top-Level Node, all Subnodes are missing.

 

 


What am I supposed to do?

Thanks.
Tags
TreeView
Asked by
Christian Sommer
Top achievements
Rank 1
Answers by
Roland
Top achievements
Rank 1
Peter
Telerik team
Christian Sommer
Top achievements
Rank 1
Share this question
or