title: Making a specific node expand based on the navigate URLs of its children
body: <p>So I have a TreeView and it has about 7 parent nodes that have 3-5 children each. All of these children nodes when click navigate to a URL. What I would like to do is have one parent node auto-expand based on the URL and the other parent nodes to collapse. </p>
  
  <p>If that wasn't clear, here is an example:</p>
  
  <pre><code>Root
   |
   |--Admin
   |  |
   |  |--Add.aspx
   |  |--Delete.aspx
   |
   |
   |
   |--Purchases
      |
      |--Orders.aspx
      |--Stock.aspx
  </code></pre>
  
  <p>Lets say the user clicked on Orders.aspx, this would navigate them to that page, and when it does, I would want the tree view to collapse all parent nodes, and expand the current parent node. So Admin would be collapsed and Purchases would be expanded.</p>
  
  <p>What I've attempted so far is this:</p>
  
  <pre><code>Protected Sub resize(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.Load
      For Each node As TreeNode In (CType(sender, TreeView)).Nodes
          If node.NavigateUrl = GetCurrentPage() Then
              For Each parentN As TreeNode In (CType(sender, TreeView)).Nodes
                  If Not (parentN.Parent.Selected = True And node.Parent.Text = parentN.Parent.Text) Then
                      parentN.Collapse()
                  Else : parentN.Expand()
                  End If
              Next
          End If
      Next
  End Sub
  
  
  Public Shared Function GetCurrentPage() As String
      Return System.IO.Path.GetFileName(HttpContext.Current.Request.Url.AbsolutePath).ToLower
  End Function
  </code></pre>
  
  <p>I'm not really sure how to go about this.</p>