Monday, 9 March 2009

Adding a Sitemap to ASP.Net application

It is always a good practice to implement some navigation system for a website that has more than one web implements various navigation controls including
Sitemappath ,TreeView,Menu.All these three controls use SiteMapDataSource which fetchs data from either xml file called web.sitemap through xmlSiteMapProvider or from database through custom sitemap provider.

Implement a Sitemap with Web.sitemap

On project->Right Click->select Add New Item.

Select Sitemap from the template and Click Add

Add aspx pages paths to sitemapnode node in web.sitemap file

version="1.0" encoding="utf-8"

<siteMap xmlns="">

<siteMapNode title="Home" description="Home" url ="~/default.aspx"

<siteMapNode title="Register"
Register New
" url ="~/Register.aspx"



Place a SitemapDataSource,SitemapPath,TreeView Controls on Master page.Set name property of SitemapDatasource.

Sitemapdatasource is

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


<asp:SiteMapPath ID="SiteMapPath1" runat="server" Font-Names="Verdana" Font-Size="Small"

PathSeparator=" >" >

<PathSeparatorStyle Font-Bold="True" ForeColor="#507CD1" />

<CurrentNodeStyle ForeColor="#333333" />

<NodeStyle Font-Bold="True" ForeColor="#284E98" />

<RootNodeStyle Font-Bold="True" ForeColor="#507CD1" />


Add tree view and set its datasource to sitemapdatasource.

<asp:TreeView ID="TreeView1" runat="server" DataSourceID="dtmap" ImageSet="Arrows"


<ParentNodeStyle Font-Bold="False" />

<HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />

<SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px"

VerticalPadding="0px" />

<NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black" HorizontalPadding="5px"

NodeSpacing="0px" VerticalPadding="0px" />


No comments:

Post a Comment