Geeks With Blogs
Rajiv Popat blog

Just came across a tree view tweak which I thought would be worth sharing. So, here it goes –

The Requirement: We were using the ASP.NET 2.0 Tree View in one of our projects. Instead on Navigating to a URL when the parent node “link” is clicked we needed the Node to Toggle Collapse and Expand exactly like it does when the tiny + button is clicked.

The Solution: Used the TreeView_Toggle Function. So if I want the first Node To Toggle When It’s link is clicked the code looks like:

string TClientID = MyTreeView.ClientID;
// in the below Javascript code all 0’s can by dynamically replaced by the node you want to toggle.
MyTreeView.Nodes[0].NavigateUrl = "javascript:TreeView_ToggleNode(" + TClientID + "_Data,0," + TClientID + "n0" + ",' '," + TClientID + "n0" + "Nodes);"

Code Source:

Any Better ways of doing this, anyone? I’ve thought of using the SelectAction but that does NOT toggle on click. It just Expands!! Maybe Microsoft Should’ve put in a SelectToggle Action instead of just SelectExpand and Toggle Instead of just Expand Action!!

Posted on Thursday, March 16, 2006 8:38 PM Cookbooks And Articles | Back to top

Comments on this post: TreeView Tweak!

# re: TreeView Tweak!
Requesting Gravatar...
Thank u very much! That what I was searching for!!!
Left by Alexander on Apr 16, 2011 4:54 AM

# re: TreeView Tweak!
Requesting Gravatar...
Good One...
Left by Alex on Jul 26, 2012 1:51 AM

Your comment:
 (will show your gravatar)

Copyright © Rajiv Popat | Powered by: