SelectedNode of TreeView is not highlighted after selection


I am developing an 2.0 c# application.
I am using a treeView.
After selecting a node the page postsback and the node I selected is not highlighted.
How can I keep it highlighted after the postback?

Who is Participating?
TSmoothConnect With a Mentor Commented:
You generally have to do it when you populate the treeview dynamically. In other words, as you are building the treeview by adding nodes to it, check the value of each node with your saved session value and if they match, set the node's selected property to true.
Are you adding the treeview to the page dynamically or is it created declaratively in the .aspx?
RelegenceAuthor Commented:
It is added dynamically
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Hitesh ManglaniConnect With a Mentor Commented:
you can store the selected item in a variable and after postback assign treeview's selected item to this variable
Since the treeview is added dynamically, it is re-created on every single post back and thus loses all of it's state information. You needed to store this information between post backs which can be done using a hidden form field, viewstate, or the session.
RelegenceAuthor Commented:
Can you please give an example of setting the selectedNode of a treeView, after I have saved the selectedNode in a session variable.
As far as I can see, the "SelectedNode" property is only for 'get' and not for 'set'
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.