Sri Lanka .NET Forum
a mission and a vision with .NET

Dynamic Menu in ASP.NET (C#)

Get Microsoft Silverlight

rated by 0 users
This post has 15 Replies | 3 Followers

Top 500 Contributor
Newbie
Points 555
bhanu Posted: 01-08-2008 2:56 PM

 I have to create a web site admin panel , with functionality of adding or removing menus and sub menus.When the admin log to the site, he should be add new menus , new sub menus and remove also. 

Thanks

Bhanu Dissanayake 

Top 10 Contributor
Dating the forum
Points 36,179

Can you be bit specific? Like what kind of menus?

You can user asp.net menu control for this and store its items hierarchy in a DB or XML file and retrieve it on runtime  

 

Jinath Premaratne Microsoft MVP (ASP/ASP.NET) www.jinath.net

  • | Post Points: 90
Top 500 Contributor
Newbie
Points 555

Thx Jinath 4 quick reply.If I can use XML file , It's better.

Bhanu

 

 

  • | Post Points: 10
Top 500 Contributor
Newbie
Points 555

I found a code and i edited it littlebit. Can u help to change this code for dynamically updating ......

// ------------------------------------------------------------------------------------------------------------------------------------------

 

  void Page_Load(Object sender, EventArgs e)
  {
   
    // Create a new Menu control.
    Menu newMenu = new Menu();
         
    // Set the properties of the Menu control.
    newMenu.ID = "NavigationMenu";
    newMenu.DisappearAfter = 2000;
    newMenu.Orientation = Orientation.Horizontal;
    newMenu.Target = "_self";
    newMenu.StaticMenuItemStyle.ForeColor = System.Drawing.Color.Black;
    newMenu.DynamicMenuItemStyle.ForeColor = System.Drawing.Color.Gray;
    newMenu.DynamicMenuItemStyle.BorderColor = System.Drawing.Color.Blue;
    newMenu.DynamicMenuItemStyle.BackColor = System.Drawing.Color.AntiqueWhite;
    newMenu.DynamicMenuItemStyle.BorderStyle = BorderStyle.Outset;
   
    newMenu.StaticMenuStyle.BorderWidth = 1;
    newMenu.StaticMenuStyle.BorderStyle = BorderStyle.Ridge;
    newMenu.StaticMenuStyle.BackColor = System.Drawing.Color.Fuchsia;
     
     
// newMenu.DynamicMenuItemStyle.ItemSpacing = 0;
    newMenu.DynamicMenuItemStyle.BorderWidth = 1;
   
// Create the menu structure.
// Menu 2 --------------------------------------------------------------------------------  
     
    // Create the root menu item.
    MenuItem homeMenuItem;     
    homeMenuItem = CreateMenuItem("Home  ", "Home.aspx", "Home");
   
    // Create the submenu items.
    MenuItem musicSubMenuItem;
    musicSubMenuItem = CreateMenuItem("Music", "Music.aspx", "Music");
   
    MenuItem moviesSubMenuItem;
    moviesSubMenuItem = CreateMenuItem("MoviesGooooooogle", "Movies.aspx", "Movies");
     
// Menu 2 --------------------------------------------------------------------------------
// create another root menu item
    MenuItem ProductMenuItem;
    ProductMenuItem = CreateMenuItem("Products", "Products.aspx", "This is Product");
     
     
    // Add the submenu items to the ChildItems
    // collection of the root menu item.
    homeMenuItem.ChildItems.Add(musicSubMenuItem);
    homeMenuItem.ChildItems.Add(moviesSubMenuItem);

// ***************************************************************************************
     
    // Add the root menu item to the ItemsCollection
    // of the Menu control.
    newMenu.Items.Add(homeMenuItem);
    newMenu.Items.Add(ProductMenuItem);
   
    // Add the Menu control to the Controls collection
    // of the PlaceHolder control.
    MenuPlaceHolder.Controls.Add(newMenu);   
  }
 
  MenuItem CreateMenuItem(String text, String url, String toolTip)
  {
    // Create a new MenuItem object.
    MenuItem menuItem = new MenuItem();
   
    // Set the properties of the MenuItem object using
    // the specified parameters.
    menuItem.Text = text;
    menuItem.NavigateUrl = url;
    menuItem.ToolTip = toolTip;
   
    return menuItem;   
  }

 

  • | Post Points: 30
Top 10 Contributor
Forum MAD
Points 24,138

http://aspalliance.com/822

If you read above mentioned article, you can identify how to manage Database Driven Hierarchical Menu easily. It is only use ASP.NET Menu, XmlDataSource and XSLT file. So, I guess, you better to try it. Smile

Chandana N. Athauda
(MVP - Development Tools - C#)
http://www.yeschandana.com

  • | Post Points: 10
Top 500 Contributor
Newbie
Points 150

Hello Sir,

             Iam S.Janaki from Chennai.I want to know how to add the submenus to a menu control dynamically using javascript.

My email ID is sjanaki1984@gmail.com. Please reply sir

With Regards

SJanaki

  • | Post Points: 50
Top 10 Contributor
Insane Poster
Points 15,633

HI

i dont think that you can add submenus using javascripts for ASP menu control.

but you can use ASP codings with Ajax.

 

**** this is a comunity. dont use "Sir" please Smile.

  • | Post Points: 50
Top 10 Contributor
Dating the forum
Points 36,179
what menu control ? is ita HTML comtrol or just a ASP.NET control ? if so you can use getelementsbytagname and get the main menu and add the sub meanus to it

Jinath Premaratne Microsoft MVP (ASP/ASP.NET) www.jinath.net

  • | Post Points: 50
Top 500 Contributor
Newbie
Points 150
Hello Thankx For your Reply.I already created a dynamicMenu using Javascript which retrieves data from DB.Now i want to add a submenu to it further Like in the Name Column say Janaki display's further if i move my mouse over the name janaki it should have another submenu. Im not getting how to display that.Please help with it as i recently joined the company.Thast why sjanaki1984@gmail.com. Bye
  • | Post Points: 30
Top 500 Contributor
Newbie
Points 150
its like this .If you want ill post my enite code here
  • | Post Points: 10
Top 500 Contributor
Newbie
Points 150
<div id="drop1" runat="server" onmouseover="OnstayUp(this)" onmouseout="OnRemove(this)" width="150" style="visibility:hidden; position:absolute" >

<table onmouseover="OnstayUp(this)" onmouseout="OnRemove(this)" width="150" border="1" cellspacing="0" cellpadding="0" >

<tr>

<td width="100" id="sub11" onmouseover="ChangeBackColor(sub11);" onmouseout="ChangeNormalColor(sub11);"></td>

</tr>

<tr>

<td width="100" id="sub12" onmouseover="ChangeBackColor(sub12);" onmouseout="ChangeNormalColor(sub12);"></td>

</tr>

<tr>

<td width="100" id="sub13" onmouseover="ChangeBackColor(sub13);" onmouseout="ChangeNormalColor(sub13);"></td>

</tr>

<tr>

<td width="100" id="sub14" onmouseover="ChangeBackColor(sub14);" onmouseout="ChangeNormalColor(sub14);"></td>

</tr>

<tr>

<td width="100" id="sub15" onmouseover="ChangeBackColor(sub15);" onmouseout="ChangeNormalColor(sub15);"></td>

</tr>

</table>

</div>

 

If you like ill post the entire code here

Plz help me with this

  • | Post Points: 10
Top 500 Contributor
Newbie
Points 150
<div id="drop1" runat="server" onmouseover="OnstayUp(this)" onmouseout="OnRemove(this)" width="150" style="visibility:hidden; position:absolute" >

<table onmouseover="OnstayUp(this)" onmouseout="OnRemove(this)" width="150" border="1" cellspacing="0" cellpadding="0" >

<tr>

<td width="100" id="sub11" onmouseover="ChangeBackColor(sub11);" onmouseout="ChangeNormalColor(sub11);"></td>

</tr>

<tr>

<td width="100" id="sub12" onmouseover="ChangeBackColor(sub12);" onmouseout="ChangeNormalColor(sub12);"></td>

</tr>

<tr>

<td width="100" id="sub13" onmouseover="ChangeBackColor(sub13);" onmouseout="ChangeNormalColor(sub13);"></td>

</tr>

<tr>

<td width="100" id="sub14" onmouseover="ChangeBackColor(sub14);" onmouseout="ChangeNormalColor(sub14);"></td>

</tr>

<tr>

<td width="100" id="sub15" onmouseover="ChangeBackColor(sub15);" onmouseout="ChangeNormalColor(sub15);"></td>

</tr> </table>

</div>

 

If you like ill post the entire code here

Plz help me with this

  • | Post Points: 10
Top 10 Contributor
Insane Poster
Points 15,633

Hi

 

in this case you can use nother layer for the submenu.

creat a normal menu within that layer and disply it only when u move the mouse over to the parent menu.

hide it when u leave the parent menu, 

  • | Post Points: 30
Top 500 Contributor
Newbie
Points 150

Hello Bhashitha,

                      Thankx for your reply sir.But the problem is i never understood what you said.I even asked all here they are telling i dont know.The very problem is im fresher that too trainee.This is the first time im using computers..NET i never had worked nor any trainig is given for me bcoz of which i find very difficult.Please understand my problem and help me

With Regards

S.Janaki

sjanaki1984@gmail.com

  • | Post Points: 30
Top 10 Contributor
Insane Poster
Points 15,633

HI can u attacth the full website and can u send a image of the final output that u want.

  • | Post Points: 10
Page 1 of 2 (16 items) 1 2 Next > | RSS
This space is available for you to advertise. Please contact admin@dotnetforum.lk for more details on how to advertise on the .NET Forum.
Copyright © Sri Lanka .NET Forum. All Rights Reserved. Terms of Use | Privacy Policy