Click here to Skip to main content
Rate this: bad
good
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 1:11am
Edited 6-Aug-12 21: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 at 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
0 DamithSL 390
1 Maciej Los 217
2 OriginalGriff 213
3 BillWoodruff 130
4 Garth J Lancaster 90
0 OriginalGriff 7,953
1 DamithSL 6,139
2 Sergey Alexandrovich Kryukov 5,449
3 Maciej Los 5,293
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 7 Aug 2012
Copyright © CodeProject, 1999-2014
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