Getting Data for a Node

2 posts, 0 answers
  1. Aaron
    Aaron avatar
    1 posts
    Member since:
    Nov 2010

    Posted 26 Sep 2012 Link to this post

    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?
  2. Plamen
    Plamen avatar
    2724 posts

    Posted 01 Oct 2012 Link to this post

    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)
       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.

    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.
  3. DevCraft R3 2016 release webinar banner
Back to Top