Add link to the right of radtreeNode

1 Answer 7 Views
TreeView
Jerry
Top achievements
Rank 1
Jerry asked on 04 Aug 2025, 05:46 PM

Hello,

I'm loading a RadTreeView from an xml file.  This has been working fine for a long time.

I've been tasked with adding a text link to another page to the right of specific nodes.

Since I'm using LoadContentFile of my RadTreeView, I'm not sure if there is a way to manipulate the nodes to add a link when loading data.

In my example below I need to find a way to add the Section links to the right of my nodes.  Can I add the section text and url as properties of a node in my xml?

Example layout

-Top

-2000s

-2021 Section 1

-2022  Section 1

-2023 Section 2

Thank you

1 Answer, 1 is accepted

Sort by
0
Vasko
Telerik team
answered on 07 Aug 2025, 07:12 AM

Hello Jerry,

You can achieve this by extending the XML structure to include the link you wish to go to as the NavigateUrlField property when binding the fields. With it, you can include a HyperLink inside a  NodeTemplate to render the the link:

<Tree>
	<Node Text="Desktop" Expanded="True" ToolTip="Desktop" Url="Default2.aspx">
		<Node Text="Administrator" Url="Default3.aspx" Expanded="True">
			<Node Text="AppData" Url="Default4.aspx">
				<Node Text="Microsoft"  Url="Default5.aspx"/>
			</Node>
			<Node Text="Contacts" />
			<Node Text="Downloads"  Url="Default6.aspx"/>
		</Node>
	</Node>
</Tree>
<telerik:RadTreeView ID="RadTreeView2" runat="server" DataSourceID="XmlDataSource1" OnNodeDataBound="RadTreeView1_NodeDataBound">
    <NodeTemplate>
        <%# DataBinder.Eval(Container, "Text") %>
        <asp:HyperLink ID="SectionLink" runat="server" Visible="false"></asp:HyperLink>
    </NodeTemplate>
    <DataBindings>
        <telerik:RadTreeNodeBinding DataMember="Node" TextField="Text" NavigateUrlField="Url" ExpandedField="Expanded"></telerik:RadTreeNodeBinding>
    </DataBindings>
</telerik:RadTreeView>

<asp:XmlDataSource runat="server" ID="XmlDataSource1" DataFile="TreeView.xml" XPath="/Tree/Node"></asp:XmlDataSource>

After that, use the NodeDataBound event to set the properties of the link:

protected void RadTreeView1_NodeDataBound(object sender, RadTreeNodeEventArgs e)
{
    string url = e.Node.NavigateUrl;

    if (!string.IsNullOrEmpty(url))
    {
        HyperLink link = (HyperLink)e.Node.FindControl("SectionLink");

        if (link != null)
        {
            link.Text = url;
            link.NavigateUrl = url;
            link.Visible = true;
            link.Style.Add("margin-left", "10px");
        }
    }
}

    This method keeps your XML data-driven and allows you to control which nodes have a link on the right, without affecting your existing structure.

        Regards,
        Vasko
        Progress Telerik

        Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
        Tags
        TreeView
        Asked by
        Jerry
        Top achievements
        Rank 1
        Answers by
        Vasko
        Telerik team
        Share this question
        or