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.


help
which I have written in xml is <? xml version = "1.0" encoding = "utf-8" ?> < menu > < menuItem mnuName = "User" > < submenu > < menuItem > < text > Home< / text > < width > 150< / width > < url > Home.aspx< / url > < / menuItem > < menuItem > < text > About Us< / text > < width > 150< / width > < url > About us.aspx< / url > < / menuItem > < menuItem > < text > Contact Us< / text > < width > 150< / width > < url > Contact us.aspx< / url menuItem > < menuItem > < text > Gallery< / text > < width > 150< / width > < url > Gallery.aspx< / url > < / menuItem > < menuItem > < text > Careers< / text
507CD1" / > <DynamicSelectedStyle BackColor = "#507CD1" / > <DynamicMenuItemStyle HorizontalPadding = "1px" VerticalPadding = "2px" BackColor = "#000099" ForeColor = "White" / > <Items> <asp:MenuItem Text = "About Us" Value = "About Us"> <asp:MenuItem Text = "Our Team" Value = "Our"> < / asp:MenuItem> <asp:MenuItem Text = "CEO Speaks" Value = "CEO Speaks"> < / asp:MenuItem> <asp:MenuItem Text = "Our Philosophy" Value = "Our Philosophy"> < / asp MenuItem> < / asp:MenuItem> <asp:MenuItem Text = "Services" Value = "New Item"> <asp:MenuItem Text = "Free Quotes" Value = "Free Quotes
object sender, RoutedEventArgs e) { Point point = GetControlPosition(PathImage); cmnu = new System.Windows.Controls. ContextMenu (); List < MenuItem > list = new List < MenuItem > (); list = LoadContextMenu(); foreach ( MenuItem item in list) { cmnu.Items.Add(item); } cmnu.Margin = new Thickness (point.X, point.Y a ContextMenu . The items of a context menu are normal MenuItems . <RichTextBox > <RichTextBox .ContextMenu > <ContextMenu > <MenuItem Command = "Cut" > <MenuItem .Icon > <Image Source = "Images / cut.png" / > < / MenuItem .Icon > < / MenuItem > <MenuItem Command = "Copy" > <MenuItem .Icon > <Image Source = "Images / copy.png" / > < / MenuItem .Icon > < / MenuItem > <MenuItem Command = "Paste
Sal? alle zusammen Hat jemand eine Idee, warum ich in dem an meinem Code falsch? Hirarchie - -> Hirarchie, angezeigt wenn Maus auf Produkte zeigt. - -> Value = "Nonfood"> < / asp:MenuItem> > <!- - 2. Hirarchie, angezeigt wenn Maus auf Produkte zeigt. - -> 1. Hirarchie - -> Value = "Freizeit"> < / asp:MenuItem> > <!- - 2. Hirarchie Angezeigt wenn Maus auf Dienstleistungen zeigt- -> Value = "Business"> < / asp:MenuItem> > <!- - 2. Hirarchie angezeigt wenn Maus auf Dienstleistungen zeigt - -> Viele liebe Gr?sse Tamara Sal? alle IN welchem Men? pr?fe ich das ? Viele liebe Gr?sse Tamara keywords: Menu, und, Menuitem, , Menuitem, nicht, sichtbar description: Sal alle zusammen Hat jemand eine Idee, warum ich in dem folgenden
I am generating a menu error on highlighted line. . Error: 'Click' is not an event of 'System.Web.UI.WebControls.MenuItem'. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim menu1 As New Menu Dim menuitem As New MenuItem menu1 = CType(Master.FindControl("Menu1"), Menu) menu1.Height = 200 menuitem = New MenuItem menuitem.Text = "Menu1" menu1.Items.Add(menuitem) AddHandler menuitem.Click, AddressOf Menu1Click menuitem = New MenuItem menuitem.Text = "Menu2" menu1.Items.Add(menuitem
DynamicSelectedStyle BackColor = "#507CD1" / > < DynamicMenuItemStyle HorizontalPadding = "5px" VerticalPadding = "2px" / > < StaticHoverStyle BackColor = "#284E98" ForeColor = "White" / > < Items > < asp : MenuItem Text = "Home"> < / asp : MenuItem > < asp : MenuItem Text = "Student Detail"> < asp : MenuItem Text = "Add"> < / asp : MenuItem > < asp : MenuItem Text = "View"> < / asp : MenuItem > < asp : MenuItem Text = "Remove"> < / asp : MenuItem > < / asp : MenuItem > < asp : MenuItem Text = "Teacher Detail"> < asp : MenuItem Text = "Add
Item In Run Time in WPF reply ASAP Hi, try this / / Add to main menu MenuItem newMenuItem1 = new MenuItem(); newMenuItem1.Header = "Test 123" ; this .MainMenu.Items.Add(newMenuItem1); / / Add to a sub item MenuItem newMenuItem2 = new MenuItem(); MenuItem newExistMenuItem = (MenuItem) this .MainMenu.Items[0]; newMenuItem2.Header = "Test 456" ; newExistMenuItem.Items.Add(newMenuItem2); hope this will to a control and displayed at the right mouse click. ContextMenu contains a list of MenuItem, which represent the command or option on which user initiate an action or command. In this article I would discus how to create ContextMenu and MenuItem at design time and run time, their properties and event handling. Design Time Creation: Context
in asp.net like this; <asp:Menu ID = "Menu1" runat = "server" StaticDisplayLevels = "3"> <Items> <asp:MenuItem Text = "File" Value = "File"> <asp:MenuItem Text = "New" Value = "New"> < / asp:MenuItem> <asp:MenuItem Text = "Open" Value = "Open"> < / asp:MenuItem> < / asp:MenuItem> <asp:MenuItem Text = "Edit" Value = "Edit"> <asp:MenuItem Text = "Copy" Value = "Copy"> < / asp:MenuItem> <asp:MenuItem Text = "Paste" Value = "Paste"> < / asp:MenuItem> < / asp
Hi., i am working in static menu item when mouse over. my code is. < asp : Menu ID = "Menu1" runat = "server"> < Items > < asp : MenuItem Text = "home" Value = "home"> < asp : MenuItem Text = "vision" Value = "vision"> < / asp : MenuItem > < / asp : MenuItem > < asp : MenuItem Text = "about us" Value = "about us"> < asp : MenuItem Text = "founder" Value = "founder"> < / asp : MenuItem > < / asp : MenuItem > < / Items > < / asp : Menu > and the same code is working in other machine But
sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim menuItems() As MenuItem = _ New MenuItem() _ {New MenuItem("Casa"), _ New MenuItem("Empresa"), _ New MenuItem("Oficina"), _ New MenuItem("Otra")} Dim BotonMenu As New ContextMenu(menuItems) BotonMenu.Show(Button1, New System.Drawing.Point(1 necesito de su ayuda. Garcias de antemano. VB.NET - Spanish Discussions System.Drawing.Point (1) MenuItem.setAttribute (1) System.EventArgs (1) EventArgs (1) MenuItem (1) Button2.Click (1) System.Object (1) Popup (1) Hola Juan, para saber que item