Edit this page

Using Custom Attributes Server-side

Access attributes through the RadTreeNode Attributes collection by specifying a key name:

node.Attributes["MyCustomAttributeKey"] = "Some value";
node.Attributes("MyCustomAttributeKey") = "Some value"

The example below iterates the Attributes collection of a selected node and displays the key names and values in a RadTextBox.

RadTreeView Custom Attributes

<telerik:RadTreeView RenderMode="Lightweight" ID="RadTreeView1" runat="server" OnNodeClick="RadTreeView1_NodeClick"
    Skin="Black">
    <Nodes>
        <telerik:RadTreeNode runat="server" Text="Alpine Parka" ProductNumber="AP0234" ProductColor="Blue"
            ProductSize="XL">
        </telerik:RadTreeNode>
        <telerik:RadTreeNode runat="server" Text="Expedition Parka" ProductNumber="EP3456"
            ProductColor="Red" Size="M">
        </telerik:RadTreeNode>
        <telerik:RadTreeNode runat="server" Text="Goosedown Jacket" ProductNumber="GJ6549"
            ProductColor="Yellow" Size="L">
        </telerik:RadTreeNode>
    </Nodes>
</telerik:RadTreeView>

        protected void RadTreeView1_NodeClick(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e)
        {    
            foreach (string key in e.Node.Attributes.Keys)    
            {        
                tbNode.Text += key + ": " + e.Node.Attributes[key] + System.Environment.NewLine;    
            }
        }


        Protected Sub RadTreeView1_NodeClick(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadTreeNodeEventArgs)
            For Each key As String In e.Node.Attributes.Keys
                tbNode.Text += key + ": " + e.Node.Attributes(key) + System.Environment.NewLine
            Next
        End Sub