title: How to loop through menu items in including all level menu items (Asp Vbnet )
body: <p><strong>Here is my Code</strong></p>
  
  <pre><code>Protected Sub NavMenu_Init(sender As Object, e As EventArgs) Handles NavMenu.PreRender
      Dim a As String = Replace(Request.Url.AbsolutePath, "/Home.aspx", "/")
      For Each i As MenuItem In NavMenu.Items
          If i.Target = a And Not i.Target = "" Then
              i.Selected = True
          End If
          If i.Target = "" Then
              i.Selected = False
          End If
          For Each aa As MenuItem In i.ChildItems
              If aa.Target = a And Not aa.Target = "" Then
                  aa.Selected = True
              End If
              If aa.Target = "" Then
                  aa.Selected = False
              End If
              For Each b As MenuItem In aa.ChildItems
                  If b.Target = a And Not b.Target = "" Then
                      b.Selected = True
                  End If
                  If b.Target = "" Then
                      b.Selected = False
                  End If
              Next
          Next
      Next
  End Sub
  </code></pre>
  
  <p>The problem is for each child level in menu i need to  repeat code.</p>
  
  <p><em>I need to know that is there any way to loop all menu levels, regardless how many levels, at once, with only one for each function.</em></p>
  
  <p><strong>Someway Like</strong></p>
  
  <pre><code>For Each i As MenuItem In NavMenu.Items and childitems
              If i.Target = a And Not i.Target = "" Then
                  i.Selected = True
              End If
              If i.Target = "" Then
                  i.Selected = False
              End If
  Next
  </code></pre>
  
  <p><strong>Thanks in advance</strong></p>