Click here to Skip to main content
14,927,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
heyy..

I have use asp menu control (vertical)(dynamically)...IN this menu having child menu showing on bottom (last) position ..but I want this child menu on first(top) position ...Is there any solution ..

here is my Menu :

XML
<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal" Width="450px" Height="100%">
                <DynamicMenuStyle CssClass="submenu" />
                   <LevelMenuItemStyles>
                       <asp:MenuItemStyle CssClass="level1" />
                       <asp:MenuItemStyle CssClass="level2" />
                       <asp:MenuItemStyle CssClass="level2" />
                       <asp:MenuItemStyle CssClass="level2" />
                       <asp:MenuItemStyle CssClass="level2" />
                   </LevelMenuItemStyles>
                   <DynamicMenuItemStyle CssClass="level2"   />
                   <Items>
                       <asp:MenuItem NavigateUrl="~/ContentPages/Common/HomeDashboard.aspx"
                           Text="Home" Value="Home"></asp:MenuItem>
                   </Items>
               </asp:Menu>

code:-
C#
private void LoadMenu()
        {
            int roleId;
            if (SessionManager.Current.RoleId != null)
            {
                int.TryParse(SessionManager.Current.RoleId.Value.ToString(), out roleId);

                List<menuitemex> menuByRole = GlobalCacheManager.GetMenuByRole(roleId);

                MenuItem topNode = new MenuItem();
                foreach (MenuItemEx menu in menuByRole)
                {
                    if (menu.ChildMenus != null && menu.ChildMenus.Count > 0)
                    {
                        MenuItem rootNode = new MenuItem();
                        rootNode.Text = menu.MenuName;

                        rootNode.Value = menu.MenuId.ToString();

                        //topNode.ChildItems.Add(rootNode);
                        Menu1.Items.Add(rootNode);
                        foreach (var item in menu.ChildMenus)
                        {
                            AddChildRecursively(rootNode, item);

                        }

                    }
                }
            }

            //  Menu1.Items.Add(topNode);
        }

C#
public static void AddChildRecursively(MenuItem parentNode, MenuItemEx menu)
       {

           MenuItem rootNode = new MenuItem();
           rootNode.Text = menu.MenuName;
           rootNode.Value = menu.MenuId.ToString();
           rootNode.NavigateUrl = menu.PageUrl;
           parentNode.ChildItems.Add(rootNode);

           if (menu.ChildMenus != null && menu.ChildMenus.Count > 0)
           {
               foreach (var item in menu.ChildMenus)
               {
                   AddChildRecursively(rootNode, item);
               }

           }
       }
Posted
Updated 27-Jun-13 20:50pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900