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
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.

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
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
submeni item in men (WPF) Silverlight / WPF 06-Jun-13 10:02 AM hello frnds < MenuItem.ItemsPanel > < ItemsPanelTemplate > < VirtualizingStackPanel Orientation = "Horizontal" / > < / ItemsPanelTemplate > i have this code in comple time . i want set run time change the orientation of submenu. private void MenuHeader(String HeaderName, string imgname) { MenuItem item = new MenuItem(); item.Header = HeaderName; Image img = new Image(); img.Width = 45; img.Height = 45; img.Source know if it not working fr you. item .Orientation = Orientation.Horizontal; Regards D Setting to menuitem as shown above won't help. You need to modify the Template (the ItemsPanelTemplate ) used in your MenuItem. You need to use the SetValue method of the FrameworkElementFactory and set the desired properties new ItemsPanelTemplate(feFactory); Thank you. hi, Here below code add image in submenu in menu < MenuItem Header = "Database" IsCheckable = "true" Foreground = "LightGreen" FontSize = "16"> < MenuItem.Icon > < Image Source = "Database.png" Width = "20" Height = "20" / > < / MenuItem.Icon > < MenuItem.Background > < ImageBrush ImageSource = "Database.png" Stretch = "Fill" / > < / MenuItem.Background > < / MenuItem > For more detail
Hi, How to Get Index of the Parent menuitem from its Child menuItem in the click event of child menu item Try this Example code < Grid.Resources > < ContextMenu x:Key = "GridContextMenu" Opened = "ContextMenu_Opened" > < MenuItem Header = "Hello" / > < MenuItem Header = "Goodbye" / > < / ContextMenu > < Style TargetType = "{x:Type igDP:DataRecordPresenter}" x:Key = "ContextMenuRecordStyle1" > < Setter Property = "ContextMenu Enabled = True End Sub Hope this helps, keywords: RoutedEventArgs, Silverlight, WPF, ShowDialog, ContextMenu, Show, Parent menuitem, toGet, Click description: How toGet Index of the Parent menuitem from its Child menuItem Hi, How to Get Index of the Parent menuitem from its