5,667,575 members and growing! (16,980 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Intermediate

ASP.NET Menu using Sitemap and MasterPage

By S.Vinothkumar

ASP.NET Menu using Sitemap and MasterPage
C# 2.0, C#, Windows, .NET, .NET 2.0, WebForms, ASP.NET, VS2005, Visual Studio, Dev

Posted: 23 Aug 2007
Updated: 23 Aug 2007
Views: 16,160
Bookmarked: 7 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
5 votes for this Article.
Popularity: 1.22 Rating: 1.74 out of 5
4 votes, 80.0%
1
0 votes, 0.0%
2
1 vote, 20.0%
3
0 votes, 0.0%
4
0 votes, 0.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

Asp.Net menu control displays menu statically or dynamically using Sitemap Data Source control, which using site map control in ASP.Net. Here I am going to explain how to display menu using sitemap control.

A site map is made up of a series of related SiteMapNode objects. The SiteMapNodes are related in such a way as to form a hierarchy. The hierarchy contains a single root node, which is the sole node in the hierarchy that does not have a parent node. Each node in the hierarchy represents a logical section of the website. Each section can have a title, URL, description, and so on, which are modeled by the SiteMapNodes class's properties (Title, Url, Description, and so on).

Creating Sitemap file

From Visual Studio 2005 we can easily create the sitemap file by right clicking the website in the solution explorer, choosing Add NewItem, and then selecting the Site Map icon. The created file has a few XML elements.

The element can have a number of attributes. Here is some attributes which are mostly using,

- title (Specifies the title of the section).

- url (Specify the url of section. It must have unique).

- description (Specify the description of the section. Used in alt attribute).

Creating Master Page.

Create a master page in our website by right clicking the website in the solution explorer, choosing Add NewItem, and then selecting MasterPage icon. I'm going to link some aspx pages through our menu. So now we have to create some .aspx pages as a content page of masterpage. We can create aspx pages by right clicking the masterpage and choose the add content page, then rename it. Here we are going to create four pages namely Main.aspx, Menu1.aspx, Menu2.aspx and SubMenu1.aspx.

Using the code

After completing this process go to master page and copy the following code

<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1">
</asp:Menu>

<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />

<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
  </asp:contentplaceholder>

From the above, SiteMapDataSource is set to asp:Menu datasource. Then copy the following code in to sitemap file.

<sitemapnode title="Main Page" description="Main Page" url="Main.aspx" />
  <sitemapnode title="Menu one" description="Menu one" url="Menu1.aspx" />
  <sitemapnode title="Menu Two" description="Menu Two" url="Menu2.aspx" />
  <sitemapnode title="SubMenu One" description="SubMenu One" url="SubMenu1.aspx" />
  </sitemapnode />
</sitemapnode />

Now run the project …

That's it…

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

S.Vinothkumar


Hi Viewers,

I wish to all. This is Vinoth. This is where I try to condense everything that you need to know about me.

Blog:

visit my blog

Interests:

I'm passionate about a great many things and continually learning about the things that interest me. They are wearable computers, User Interface Design, Artificial life, Industrial music.






Occupation: Web Developer
Location: India India

Other popular ASP.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
  (Refresh) 
-- There are no messages in this forum --

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 23 Aug 2007
Editor:
Copyright 2007 by S.Vinothkumar
Everything else Copyright © CodeProject, 1999-2008
Web07 | Advertise on the Code Project