Can you store additional data with radTreeView?

4 posts, 0 answers
  1. David
    David avatar
    48 posts
    Member since:
    Nov 2012

    Posted 06 Dec 2012 Link to this post

    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"



  2. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 07 Dec 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. David
    David avatar
    48 posts
    Member since:
    Nov 2012

    Posted 08 Dec 2012 Link to this post

    Thanks! that worked.
  5. Marbry
    Marbry avatar
    123 posts
    Member since:
    Aug 2012

    Posted 13 Dec 2012 Link to this post

    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");
Back to Top