ASP.NET Menu using Sitemap

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.

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.

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




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



Now run the project …

That’s it…

If you want to download the program come here...

Cheers....

...VinothkumaR.




No comments: