C# AspMenu help needed

Soldato
Joined
1 Feb 2006
Posts
8,188
Been struggling to get my head around this one. I have a hierarchy of Term objects that I want to iterate through and add to an asp menu control. I think my recursive function is fine except that each time I need to add the child items to the corresponding parent item, then add the full structure to a navigation control.

See code:

Code:
private void IterateSubTerms(Term t)
        {
            if (t.Terms != null)
            {
                foreach (Term term in t.Terms)
                {
                    MenuItem childItem = new MenuItem();
                    childItem.Text = term.Name.ToString();
                    childItem.NavigateUrl = "default.aspx";
                    
                    // next line is the problem
                    myMenu.Items.Add(childItem)
                    IterateSubTerms(term);
                }
            }
        }

The line myMenu.Items.Add is the problem as this will result in only a 2-level navigation structure. Instead what I need is to be able to add child nodes to the corresponding parent node so that I have maybe 4 or 5 levels deep.

What am I missing here? I could maybe use something like myMenu.Items[0].ChildItems.Add but I have no idea where to get the index value from that would drive this.

Any help would be great.
 
Back
Top Bottom