Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Updated 6-Aug-12 20:27pm
v2

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
 
Share this answer
 
Comments
[no name] 7-Aug-12 2:40am    
dear Ashish, i have already tried that link but not success.. please give suggestion or help furtherrr
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
[no name] 7-Aug-12 3:01am    
<span>please tell me first my code for getting menu and its submenu is right or may be some changes....
if you mail the code to me so , so it greatful to me...
mail </span>
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..
 
Share this answer
 
Comments
[no name] 6-Aug-12 2:05am    
when user move the mouse over the main menu which text come from the table so its submenu as its main menuuu

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