TreeView TreeNode SelectedNode Index ValuePath Indexing, Selecting, Server Side

J

Jared

I am using a TreeView with data stored in a database and have been
trying to store a node index over a postback and re-select the node
without using javascript.

I couldn't find anything in these groups to answer my question, so I
thought somebody might find this method useful.

You can use the TreeNode.ValuePath to select a node using the
TreeView.FindNode() method.

Firstly store the value path;

Session["strNode"] = MyTreeView.SelectedNode.ValuePath;
//I am storing in a session variable here.

Then you can deselect your node if you want and carry on with other
tasks, but you can still re-select by running the following.

if (Convert.ToString(Session["strNode"]) != "")
{
TreeNode strNode =
MyTreeView.FindNode(Convert.ToString(Session["strNode"]));
strNode.Select();
Session["strNode"] = "";
}

Hope this is useful.

Jared
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top