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 page.ASP.net 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



<?xml
version="1.0" encoding="utf-8"
?>



<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">


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


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


</siteMapNode>


</siteMap>


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


Sitemapdatasource is


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




Add
Sitemappath

<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" />



</asp:SiteMapPath>



Add tree view and set its datasource to sitemapdatasource.

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

ShowLines="True">

<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" />

</asp:TreeView>






No comments:

Post a Comment