In this article I will explain with an example, how to remove HyperLink (LinkButton) from TreeView Node in ASP.Net using C# and VB.Net.
This article will illustrate how to remove HyperLink (LinkButton) from TreeView Node in ASPX page as well as from Code-Behind in ASP.Net.
 
 
Concept
The TreeView Node has a property named SelectAction which when set to None will remove the HyperLink (LinkButton).
This SelectAction property can be set in ASPX page as well as in Code-Behind.
 
 
Removing HyperLink (LinkButton) from TreeView Node from ASPX page
HTML Markup
The HTML Markup consists of ASP.Net TreeView control. The TreeView control is populated using TreeNodes and the SelectAction property for each TreeNode is set to None in order to remove the HyperLink (LinkButton).
<asp:TreeView ID="TreeView1" runat="server">
    <Nodes>
        <asp:TreeNode Text="Fruits" Value="F" SelectAction="None">
            <asp:TreeNode Text="Apple" Value="1" SelectAction="None"></asp:TreeNode>
            <asp:TreeNode Text="Mango" Value="2" SelectAction="None"></asp:TreeNode>
            <asp:TreeNode Text="Banana" Value="3" SelectAction="None"></asp:TreeNode>
        </asp:TreeNode>
    </Nodes>
</asp:TreeView>
 
 

Remove HyperLink (LinkButton) from TreeView Node from Code-Behind
HTML Markup
The HTML Markup consists of ASP.Net TreeView control.
<asp:TreeView ID="TreeView2" runat="server">
</asp:TreeView>
 
Populating the ASP.Net TreeView Control
Inside the Page Load event, Nodes are added to the TreeView control using the AddNode function.
The AddNode function accepts the Text and Value of the TreeView Node as parameters.
The Text and Value parts are assigned to the respective properties of the TreeView Node.
Finally, the SelectAction property is set to None, so that the HyperLink (LinkButton) is removed from the TreeView Node and it is not clickable.
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        TreeView2.Nodes.Add(AddNode("Vegetables", "V"));
        TreeView2.Nodes[0].ChildNodes.Add(AddNode("Carrot", "1"));
        TreeView2.Nodes[0].ChildNodes.Add(AddNode("Cauliflower", "2"));
        TreeView2.Nodes[0].ChildNodes.Add(AddNode("Potato", "3"));
    }
}
 
private TreeNode AddNode(string text, string value)
{
    return new TreeNode
    {
        Text = text,
        Value = value,
        SelectAction = TreeNodeSelectAction.None
    };
}
 
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not Me.IsPostBack Then
        TreeView2.Nodes.Add(AddNode("Vegetables", "V"))
        TreeView2.Nodes(0).ChildNodes.Add(AddNode("Carrot", "1"))
        TreeView2.Nodes(0).ChildNodes.Add(AddNode("Cauliflower", "2"))
        TreeView2.Nodes(0).ChildNodes.Add(AddNode("Potato", "3"))
    End If
End Sub
 
Private Function AddNode(ByVal text As String, ByVal value As String) As TreeNode
    Return New TreeNode With {
        .Text = text,
        .Value = value,
        .SelectAction = TreeNodeSelectAction.None
    }
End Function
 
 
Screenshot
Remove HyperLink (LinkButton) from TreeView Node in ASP.Net
 
 
Demo
 
 
Downloads