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

Can you store additional data with radTreeView?

3 Answers 174 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 06 Dec 2012, 06:59 PM
Hi, Can I somehow add additional data to a treeview node AND access it through javascript?  For example, what if I wanted to bind "category" data to be stored with each node below?

siteData.Add(new SiteDataItem(6, 2, "RadEditor", "editor"));
siteData.Add(new SiteDataItem(7, 3, "RadGrid", "grid"));
siteData.Add(new SiteDataItem(8, 3, "RadMenu", "menu"));
siteData.Add(new SiteDataItem(9, 3, "RadEditor", "editor")); 
....          
treeView.DataTextField = "Text";
treeView.DataFieldID = "ID";
treeView.DataValueField = "Value";
treeView.DataFieldParentID = "ParentID";
treeView.DataSource = siteData;
treeView.DataBind();

...Can I then pull the category value using javascript similar to how I access the value or text?

node.get_value()
"ajax"

node.get_text()
"RadControls for ASP.NET Ajax"



3 Answers, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 2
answered on 07 Dec 2012, 12:47 PM
Hey David,

You could handle the OnNodeDataBound event of the RadTreeView and set the category that way. Like so:

Code-Behind:
protected void RadTreeView1_NodeDataBound(object sender, RadTreeNodeEventArgs e)
   {
       SiteDataItem dataItem = (SiteDataItem)e.Node.DataItem;
       e.Node.Category = dataItem.Category;
   }

Then in javascript you can the category like so:

Javascript:
node.get_category()

I hope that helps.
0
David
Top achievements
Rank 1
answered on 08 Dec 2012, 01:39 PM
Thanks! that worked.
0
Marbry
Top achievements
Rank 1
answered on 13 Dec 2012, 02:38 PM
I just been adding attributes to nodes as needed to store additional data.

Set it on the server.
myRadTreeViewNode.Attributes.Add("MaxLength", MaxLengthValue);


Retrieve it on the client.
node._attributes.getAttribute("MaxLength");
Tags
TreeView
Asked by
David
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
David
Top achievements
Rank 1
Marbry
Top achievements
Rank 1
Share this question
or