Click here to Skip to main content
12,396,461 members (69,916 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# menu
Hello,,

i am using the Menu in ASP.net with c#. both the menu and sub menu come from the table. at present the sub menu display horizontally but i want to show under the its menu or on mouse over effect of that menu....

please help me and how this will be achieved.....

i want to set the menu like...

Menu1 >> menu2 >>  menu3 >> menu4
mnu1     mnu2      mnu3
mnu2
 
but it display like 
Menu1 >> menu2 >> menu3 >> menu4
when i click on menu1 it display like,,,
Menu1>>mnu1 mnu2
 
this what i not want , i want display sub menu vertically as a sub menu of its main menu....
 

i use the code like...
 

 
 if (!IsPostBack)
            {
                c.setcon();
                string menu_string = "select distinct category from ctgry";
                SqlDataAdapter menu_ad = new SqlDataAdapter(menu_string, c.getcon());
                DataSet ds_menu = new DataSet();
                menu_ad.Fill(ds_menu);
                c.close();
                for (int i = 0; i < ds_menu.Tables[0].Rows.Count; i++)
                {
                    MenuItem mnu = new MenuItem();
                    mnu.Text = ds_menu.Tables[0].Rows[i][0].ToString();
                    Menu1.Items.Add(mnu);
 
                    c.setcon();
                    string s1 = "select subctgry from subctgry where category='" + ds_menu.Tables[0].Rows[i][0].ToString() + "'";
                    SqlDataAdapter ad_sub_menu = new SqlDataAdapter(s1, c.getcon());
                    DataSet ds_sub_menu = new DataSet();
                    ad_sub_menu.Fill(ds_sub_menu);
 
                    if (ds_sub_menu.Tables[0].Rows.Count != 0)
                    {
                        for (int j = 0; j < ds_sub_menu.Tables[0].Rows.Count; j++)
                        {
                            MenuItem sub_menu = new MenuItem();
                            sub_menu.Value = ds_menu.Tables[0].Rows[i][0].ToString();
                            sub_menu.Text = ds_sub_menu.Tables[0].Rows[j][0].ToString();
                            mnu.ChildItems.Add(sub_menu);
                        }
                    }
 
                }
                c.close();
            }


<asp:Menu ID="Menu1" runat="server" Font-Size="Small" ForeColor="Black" 
                   Orientation="Horizontal" Height="23px" PathSeparator="/">
                   <staticmenuitemstyle itemspacing="2px" />
                   <dynamicmenuitemstyle font-size="Medium" forecolor="#FF0066" />
               
Regards...
Mitesh
Posted 4-Aug-12 0:11am
Updated 6-Aug-12 20:27pm
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Please follow the link for exactly as per your requirement


http://aspalliance.com/822_Building_a_Database_Driven_Hierarchical_Menu_using_ASPNET_20[^]

Thanks
Ashish
  Permalink  
Comments
AshishChaudha 7-Aug-12 2:47am
   
Mitesh, I tried that solution for one of my project and its working fine. First follow as it is code of that solution then do RND as per your requirement. OR I can mail you the code.
Thanks
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

the portion "...but i want to show under the its menu or on mouse over effect.." needs more clarification.
However see if Dynamically populating menu items from the database in ASP.NET[^] can help you..
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160721.1 | Last Updated 7 Aug 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100