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

Getting Data for a Node

1 Answer 58 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Aaron
Top achievements
Rank 1
Aaron asked on 26 Sep 2012, 03:34 PM
I'm a little stuck trying to figure out the best way to do this.

Scenario: Using the TreeView to allow a user to create, edit, and sort menu items. It's going to allow an end user to build the menu of their web site.

The data table is simple, an ID, Parent ID, Display Text, and a Sort column (Int).

I am connecting the data table to a LinqDataSource which is then attached to the TreeView. I have the data source ordering by the sort column.

I have everything set up to allow drag and drop and I'm using the NodeDrop event to handle the dragging and dropping of nodes. However, I'm running into a problem trying to get to the data in the Node. I need to access the Sort column of that row so I can resort the list. DataItem is null, which the documentation says it will be and to use custom properties or the value property. I don't use Value for anything, but even if I saved the ID to that, I would still need the sort property. Plus, since the data source orders by the sort column, I wouldn't be able to just put the sort column in as a custom property as that won't properly sort the list.

Is there a way to get and change the underlying data that is attached to that node?

1 Answer, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 01 Oct 2012, 10:11 AM
Hi Aaron,

 
You can use the DataItem in the NodeDataBound event and assign it to some Custom Attribute of the node. Here is a sample code that worked properly at my side:

protected void Page_Load(object sender, EventArgs e)
   {
       RadTreeView1.NodeClick += new RadTreeViewEventHandler(RadTreeView1_NodeClick);
   }
 
   void RadTreeView1_NodeClick(object sender, RadTreeNodeEventArgs e)
   {
       Response.Write(e.Node.Attributes["newCurtomAttribute"]);
   }
   protected void RadTreeView1_NodeDataBound(object sender, RadTreeNodeEventArgs e)
   {
       string newCurtomAttribute = (string)DataBinder.Eval(e.Node.DataItem, "Occupation");
       e.Node.Attributes["newCurtomAttribute"] = newCurtomAttribute;
   }

Hope this information will be helpful.

Greetings,
Plamen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
TreeView
Asked by
Aaron
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or