ToolBox Navigation Control Menu

Menu Web Server Control

in ASP.NET environment,This article describes you how to work with Menu Web Control.The primary mechanism of the Menu control is to create a navigation within our application.In other words, The ASP.NET Menu control enables you to add navigational functionality to your Web pages. The Menu control supports a main menu and submenus, and allows you to define dynamic menus (sometimes called "fly-out" menus).

In ASP.NET environment, Using the ASP.NET Menu control to develop both statically and dynamically displayed menus for your ASP.NET Web pages. You can configure the contents of the Menu control directly in the control, or you can specify the contents by binding the control to a data source.

Static Display

By using the StaticDisplayLevels property, we are able to control static display in the Menu control. The StaticDisplayLevels property indicates how many levels to display statically from the root of the menu. For example, menu can be expanded upto first three levels when StaticDisplayLevels is set to 3, The minimum static display level is 1, and the control will throw an exception if the value is set to 0 or a negative number.

Dynamic Display

The MaximumDynamicDisplayLevels property specifies how many levels of dynamically appearing menu nodes should be displayed after the static display level. For example, if your menu has a static level of 3 and a dynamic level of 2, the first three levels of your menu would be statically displayed, while the next two levels would be dynamic.

To Adding Menu Items

The following example shows the declarative markup for a Menu control with three items, each of which has two child items:

<asp:Menu ID="Menu1" runat="server" StaticDisplayLevels="3">
    <Items>
        <asp:MenuItem Text="File" Value="File">
            <asp:MenuItem Text="Menu1" Value="New"></asp:MenuItem>
            <asp:MenuItem Text="Menu2" Value="Open"></asp:MenuItem>
        </asp:MenuItem>
        <asp:MenuItem Text="Edit" Value="Edit">
            <asp:MenuItem Text="Menu3" Value="Copy"></asp:MenuItem>
            <asp:MenuItem Text="Menu4" Value="Paste"></asp:MenuItem>
        </asp:MenuItem>
        <asp:MenuItem Text="View" Value="View">
            <asp:MenuItem Text="Menu5" Value="Normal"></asp:MenuItem>
            <asp:MenuItem Text="Menu6" Value="Preview"></asp:MenuItem>
        </asp:MenuItem>
    </Items>
</asp:Menu>
        
 
Appearance

Along the properties of the Menu Control, We can adjust the behavior of the Menu control. Additionally, you can control the behavior of dynamic display, including the amount of time a menu node remains visible once it is displayed. For example, to change the Menu orientation from horizontal to vertical, Use the folloing,

Menu.Orientation = Orientation.Vertical;
 
Style

The following styles can be used under the Menu Control:

  • Control
  • SubMenuStyles
  • MenuItemStyles
  • SelectedItemStyles
  • HoverMenuItemStyles
Using Menus through Programmatically

Normally, The ASP.NET Menu control can be used to create navigational menus for your Web site.here,using the programmatic aspects of the ASP.NET Menu control and create two menus bound to the same Web.sitemap file that work together.statically, The first menu is displaying the menu of categories such as computer,supercomputer,mainframe. It will appear horizontally across the top of the page. The second menu is displayed horizontally below the first menu. The content of the second menu is determined by which menu item is selected in the first. Based on the current selection of the first menu, you programmatically adjust the site map data source of the second menu to show only that portion of the Web.sitemap file that is relevant to the selected category.

To create the Web.sitemap file
  • Solution Explorer --> right-click --> Add New Item.
  • choose Site Map and then click Add.
  • Add the following XML code to the new file. The XML represents a hierarchy of menu choices.
<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
  <siteMapNode title="Home">
    <siteMapNode title="Computer">
      <siteMapNode title="Hardware" url="Default.aspx?node=hardware">
        <siteMapNode title="Mouse"/>
        <siteMapNode title="Keyboard"/>
        <siteMapNode title="NetCard"/>
        <siteMapNode title="Monitor"/>
        <siteMapNode title="PC"/>
      </siteMapNode>
      <siteMapNode title="Software" url="Default.aspx?node=software">
        <siteMapNode title="Spreadsheet"/>
        <siteMapNode title="Word Processor"/>
        <siteMapNode title="Presentation"/>
        <siteMapNode title="Mail"/>
        <siteMapNode title="Games"/>
      </siteMapNode>
    </siteMapNode>
    <siteMapNode title="">
      <siteMapNode title="supercomputer" url="Default.aspx?node=consulting">
        <siteMapNode title="Hardware" url="Default.aspx?node=hardware">
        <siteMapNode title="Mouse"/>
        <siteMapNode title="Keyboard"/>
        <siteMapNode title="NetCard"/>
        <siteMapNode title="Monitor"/>
        <siteMapNode title="PC"/>
      </siteMapNode>
      <siteMapNode title="Software" url="Default.aspx?node=software">
        <siteMapNode title="Spreadsheet"/>
        <siteMapNode title="Word Processor"/>
        <siteMapNode title="Presentation"/>
        <siteMapNode title="Mail"/>
        <siteMapNode title="Games"/>
    </siteMapNode>
    <siteMapNode title="Support">
      <siteMapNode title="mainframe" url="Default.aspx?node=drivers">
        <siteMapNode title="Hardware" url="Default.aspx?node=hardware">
        <siteMapNode title="Mouse"/>
        <siteMapNode title="Keyboard"/>
        <siteMapNode title="NetCard"/>
        <siteMapNode title="Monitor"/>
        <siteMapNode title="PC"/>
      </siteMapNode>
      <siteMapNode title="Software" url="Default.aspx?node=software">
        <siteMapNode title="Spreadsheet"/>
        <siteMapNode title="Word Processor"/>
        <siteMapNode title="Presentation"/>
        <siteMapNode title="Mail"/>
        <siteMapNode title="Games"/>
    </siteMapNode>
  </siteMapNode>
</siteMap>  
                    
 
To create the first menu
  • in Design View, Include a Menu Control into the Page
  • In the Properties window, set the Orientation property to Horizontal.
  • Set MaximumDynamicDisplayLevels to 0.
  • Be sure that StaticDisplayLevels is set to 1.
  • Click the smart tag on the Menu control.
  • Choose New Data Source in the Choose Data Source drop-down list.
  • In the Data Source Configuration Wizard, choose Site Map.
  • Accept the default name of SiteMapDataSource1 and click OK.
To configure the first data source
  • In Design view, and then click the smart tag on the Menu control.
  • Click Edit MenuItem Databindings.
  • In the Menu DataBindings Editor, in the Available data bindings drop-down list, select SiteMapNode and click Add.
  • Select TextField in the Data binding properties drop-down list and select Title from the drop-down menu. Click OK.
  • Select the SiteMapDataSource control.
  • In Properties, set ShowStartingNode to False.
To create the second menu
  • In Design view, and then drag a second Menu control onto the page below the first Menu control.
  • In Properties, set Orientation to Horizontal.
  • Click the smart tag on the second Menu control.
  • Choose New Data Source in the Choose Data Source drop-down list.
  • In the Data Source Configuration Wizard, choose Site Map.
  • Accept the default name of SiteMapDataSource2 and click OK.
To configure the second data source's starting point
  • Select SiteMapDataSource2 and set its StartingNodeURL property to "Home.aspx?node=hardware".
  • Set StartingNodeOffset to -1.
  • Set ShowStartingNode to False.
To coordinate the menus in code
  • In Design View, and select Menu1.
  • In Properties, set the MenuItemClick event to Menu1_MenuItemClick.
  • Copy and paste the following code to the method.
protected void Menu1_MenuItemClick(Object sender,    
System.Web.UI.WebControls.MenuEventArgs e)
{
switch(e.Item.Value)
{
  case "Computer":
    SiteMapDataSource2.StartingNodeUrl = "Default.aspx?node=hardware";
    return;
  case "suptercomputer":
    SiteMapDataSource2.StartingNodeUrl = "Default.aspx?node=software";
    return;
  case "mainframe":
    SiteMapDataSource2.StartingNodeUrl = "Default.aspx?node=hardware";
    return;
}
}
                    
 
  • Save and run the Application.
 
Related Links

Posted by: Admin
Posted on: 9/14/2009 at 5:25 PM
Tags: , ,
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (18) | Post RSSRSS comment feed

Comments

Onlineatoz.net

Monday, September 14, 2009 5:27 PM

trackback

ToolBox Navigation Control Sitemap

ToolBox Navigation Control Sitemap

ucvhost United States

Friday, February 05, 2010 1:06 PM

ucvhost

great stuff thanks for sharing

Rapidshare United States

Wednesday, April 28, 2010 3:18 AM

Rapidshare

I\'m happy I found this blog, I couldnt discover any info on this subject matter prior to. I also run a site and if you want to ever serious in a little bit of guest writing for me if possible feel free to let me know, i\'m always look for people to check out my site. Please stop by and leave a comment sometime!

Svitlana.Net.Ua United States

Thursday, June 17, 2010 3:17 AM

Svitlana.Net.Ua

I would like to thank you for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now.

moncler men People's Republic of China

Tuesday, June 22, 2010 10:20 AM

moncler men

Here elaborates the matter not only extensively but also detailly .I support the write's unique point.It is useful and benefit to your daily life.You can go those <a href=" http://conditions-encountered.com/ " >wslmart.net </a> sits to know more relate things.They are strongly recommended by friends.Personally

няня United States

Tuesday, June 22, 2010 7:25 PM

няня

I would like to thank you for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now.
http://svitlana.net.ua/staff/category/3/ гувернантка, http://svitlana.net.ua/staff/category/5/ повар, http://svitlana.net.ua/staff/category/6/ садовник, http://svitlana.net.ua/staff/category/10/ репетитор, http://svitlana.net.ua/staff/category/4 домработница, http://svitlana.net.ua/staff/category/8/ семейная пара, http://svitlana.net.ua/pages/2/ работа няней.

e-pokeronline United States

Friday, June 25, 2010 9:29 AM

e-pokeronline

It\'s an intriguing approach. I ordinarily stumble upon ordinary thoughts on the theme but yours it\'s written in a pretty special way. Sure enough, I will revisit your website for additional information.

solar panel United States

Tuesday, June 29, 2010 6:01 AM

solar panel

Thanks for this great post it was very informative and helped me with my own project I am attempting to complete.

Магазин сантехники United States

Sunday, July 04, 2010 12:08 PM

Магазин сантехники

You have some honest ideas here. I done a research on the issue and discovered most peoples will agree with your blog.

Москва и проститутки United States

Wednesday, July 07, 2010 4:13 PM

Москва и проститутки

I really loved reading your thoughts, obviously you know what are you talking about! Your site is so easy to use too, I’ve bookmark it in my folder :-D

Новинки сантехники United States

Sunday, July 11, 2010 9:31 AM

Новинки сантехники

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts.Any way Ill be subscribing to your feed and I hope you post again soon

Проститутки United States

Monday, July 12, 2010 9:58 AM

Проститутки

You gave nice ideas here. I done a research on the issue and learnt most peoples will agree with your blog. Certainly, these practices are unfair; but they say that most of their rules are only to apply to people who overdraw.

Timberland Boots sale United States

Thursday, July 29, 2010 11:45 AM

Timberland Boots sale

Through reading more good articles to improve our quality of life. Your blog make me feel comfortable. At the sametime,http://www.timberlandshoesonline.com I will introduce you to know about a comfortable shoes that makes your life better! you can choice what you like!

Erectile Dysfunction United States

Friday, July 30, 2010 7:36 AM

Erectile Dysfunction

Im not gonna lie, Im really impressed.  Its rare for me to find something on the internet thats as entertaining and intriguing as what youve got here.  Your page is sweet, your graphics are great, and whats more, you use videos that are relevant to what youre saying.  Youre definitely one in a million, man!

Payday Loans United States

Friday, July 30, 2010 7:44 AM

Payday Loans

Your blog is outrageous!  I mean, Ive never been so entertained by anything in my life!  Your vids are perfect for this.  I mean, how did you manage to find something that matches your style of writing so well?  Im really happy I started reading this today.  Youve got a follower in me for sure!

Cialis United States

Friday, July 30, 2010 4:42 PM

Cialis

Ive been meaning to read this and just never got a chance.  Its an issue that Im very interested in, I just started reading and Im glad I did.  Youre a great blogger, one of the best that Ive seen.  This blog definitely has some information on topic that I just wasnt aware of.  Thanks for bringing this stuff to light.

Auto Insurance Quotes United States

Friday, July 30, 2010 7:32 PM

Auto Insurance Quotes

What I wouldnt give to have a debate with you about this.  You just say so many things that come from nowhere that Im pretty sure Id have a fair shot.  Your blog is great visually, I mean people wont be bored.  But others who can see past the videos and the layout wont be so impressed with your generic understanding of this topic.

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading