Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Unfortunately you can't do this in the XML. It is a short coming of the control. You will need to populate the TreeView with the XML and then traverse all of the nodes recursively and expand the branch that you need. Try the following:</p> <p>Add the OnPreRender attrobite to the TreeView control...</p> <pre><code>&lt;asp:XmlDataSource ID="oXmlDataSource" runat="server" /&gt; &lt;asp:TreeView ID="TreeView1" runat="server" EnableViewState="false" DataSourceID="oXmlDataSource" OnPreRender="TreeView1_PreRender"&gt;&lt;/TreeView&gt; </code></pre> <p>Then add the following to the code behind (I recommend adding some testing and adding try/catches)...</p> <pre><code>protected void TreeView1_PreRender(object sender, EventArgs e) { SelectCurrentPageTreeNode(TreeView1); } private void SelectCurrentPageTreeNode(TreeView tvTreeView) { tvTreeView.CollapseAll(); if (Request.Url.PathAndQuery != null) { ExpandTreeViewNodes(tvTreeView, Request.Url.PathAndQuery); } } private TreeNode ExpandTreeViewNodes(TreeView tvTreeView, string sPathAndQuery) { if (tvTreeView != null) { if (!string.IsNullOrEmpty(sPathAndQuery)) { sPathAndQuery = sPathAndQuery.ToLower(); { TreeNode tnWorkTreeNode = null; for (int iLoop = 0; iLoop &lt; tvTreeView.Nodes.Count; iLoop++) { tvTreeView.Nodes[iLoop].Expand(); tvTreeView.Nodes[iLoop].Selected = true; if (tvTreeView.Nodes[iLoop].NavigateUrl.ToLower() == sPathAndQuery) { return (tvTreeView.Nodes[iLoop]); } else { tnWorkTreeNode = ExpandTreeViewNodesR(tvTreeView.Nodes[iLoop], sPathAndQuery); } if (tnWorkTreeNode != null) { return (tnWorkTreeNode); } tvTreeView.Nodes[iLoop].Collapse(); } } } } return (null); } private static TreeNode ExpandTreeViewNodesR(TreeNode tvTreeNode, string sPathAndQuery) { TreeNode tnReturnTreeNode = null; if (tvTreeNode != null) { tvTreeNode.Expand(); if (tvTreeNode.NavigateUrl.ToLower() == sPathAndQuery) { return (tvTreeNode); } else { tnReturnTreeNode = null; for (int iLoop = 0; iLoop &lt; tvTreeNode.ChildNodes.Count; iLoop++) { tvTreeNode.ChildNodes[iLoop].Selected = true; tnReturnTreeNode = ExpandTreeViewNodesR(tvTreeNode.ChildNodes[iLoop], sPathAndQuery); if (tnReturnTreeNode != null) { return (tnReturnTreeNode); } } tvTreeNode.Collapse(); } } return (null); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload