VB.NET - Problem with asp:menu when there is no parent but there are children

Asked By Annie X on 22-Jun-12 04:22 AM
Earn up to 30 extra points for answering this tough question.
Hi, hope you can help,
I'm having a problem with an asp:menu when there is no parent but there are children

How would i check this in the last part of the code?

Many thanks AnnieX

Dim dt As New DataTable()
dt = dsListHeaders.Tables(0)
Dim drowpar As DataRow() = dt.Select("ParentID=" & 0)

'LIST PARENTS
For Each dr As DataRow In drowpar
  menuBar.Items.Add(New MenuItem(dr("AdminLinks").ToString() & " |", dr("IDtbAdminLinks").ToString(), "", dr("Url").ToString()))
Next

'LIST CHILDREN TO PARENTS
For Each dr As DataRow In dt.Select("ParentID >" & 0)
  Dim mnu As New MenuItem(dr("AdminLinks").ToString(), dr("IDtbAdminLinks").ToString(), "", dr("Url").ToString())
  menuBar.FindItem(dr("ParentID").ToString()).ChildItems.Add(mnu)
Next

Chintan Vaghela replied to Annie X on 22-Jun-12 08:36 AM
can you send me your table data with output?

So I will check here and let you know proper result
[)ia6l0 iii replied to Annie X on 22-Jun-12 01:15 PM
You would probably want to group them as 'Others' category. 

The following line, from your code sample,  selects the ones who do not have a parent id.
Dim drowpar As DataRow() = dt.Select("ParentID=" & 0)

Add a menubar item for this as "Others"
  menuBar.Items.Add(New MenuItem("Others");

Add the items to the "Others' collection. 
For Each dr As DataRow In dt.Select("ParentID =" & 0)

  Dim mnu As New MenuItem(dr("AdminLinks").ToString(), dr("IDtbAdminLinks").ToString(), "", dr("Url").ToString())
  menuBar.FindItem("Others").ChildItems.Add(mnu)
Next

Hope this helps.