Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / HTML

How to remove Hyperlink from ASP.NET TreeView Nodes Control Nodes?

5.00/5 (3 votes)
23 Sep 2010CPOL2 min read 45.3K  
A post on how to remove Hyperlink from ASP.NET TreeView Nodes Control Nodes

ASP.NET Tree view control is rendered as HTML Table – TR –TD elements. Each of the nodes has been represented as hyperlinks. Sometimes, you may not want those fields as hyperlinks and you want those nodes to be represented as static text. Many of the developers did the same using font style or CSS style change of the node, but it can be done very easily. In this small blog post, I am going to describe how you can represent a tree view node as simple text instead of hyperlink.

This can be done very easily using Tree Nodes, SelectionAction properties. SelectionAction has 4 different values. They are:

3

Select is the default option which marks node as hyperlinked and on selection of the node, it raises SelectedNodeChanged event. For Expand Option, TreeNodeExpanded event will be raised while expanding the node. “SelectExpand” raises both the SelectedNodeChanged and TreeNodeExpanded events. Now if you don’t want to make the node as simple text, just change the SelectionAction properties to “None”.

1

The above image shows how you can change the “SelectionAction” properties while creating a TreeView manually. But most of the time, bind the data from a data source with tree view dynamically, for that you can use the code snippet given below:

2

So, what does this “Select” and “None” really make change internally? Yes, when you are using Selection Action as “Select” Treeview Nodes rendered as HTML hyperlink in UI but for the “None” it rendered as "Span

The below image shows the “Span” element of TreeNode for “SelectionAction=”None””.

4

The below image shows the hyperlink mode of TreeNode for “SelectionAction=”Select””.

5

Summary

In this blog post, I have described how you can use a TreeView node without hyperlink mode. There was a question that was asked over here, where I gave the same answer. So, I thought of sharing with all of you with some detailed explanation.

Hope this will help you!

Thanks!
Abhijit


Filed under: ASP.NET, ASP.NET 4.0, Tips and Tricks

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)