Hello and welcome to my blog. Here I m going to present a very good feature
of ASP.net 2.0. While navigating our web pages we are not sure where we are or
which menu we just clicked a moment back. We need to think about that and the
Asp.net 2.0 brought a very good solution for that i.e. Site Navigation control.
Here I will show you how to use site map in our web pages. Just follow the
simple steps and you are done...
ü
Open your visual
studio .Net and create website.
ü
Click to add new
item in your website as ‘web.sitemap’, please do not rename the file name.
ü
Write the below
code in your ‘web.sitemap’
xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode
url="Default.aspx" title="Home" description="Home">
<siteMapNode
url="Page1.aspx" title="Serach" description="Search" />
<siteMapNode
url="Page2.aspx" title="Grid View Example" description="Grid View Example"
/>
siteMapNode>
siteMap>
ü
To display the
sitemap we need to use either Tree view control or Menu control in ASP.Net 2.0.’
ü
Here I m going to
use ‘TreeView’ control in our page. Write the below code in your page.
<asp:SiteMapDataSource ID="myDataSource"
runat="server" StartingNodeUrl="~/Default.aspx" />
<asp:TreeView DataSourceID="myDataSource"
ID="TreeView1"
runat="server">
asp:TreeView>
<asp:SiteMapPath id="SiteMap" BackColor="Green" CurrentNodeStyle-Font-Bold="true" ForeColor="Red" runat="server">
asp:SiteMapPath>
ü
Now our half of
the part is done. We are going to use SiteMap control which will help us to
indicate which page we are and directly to go on home page by using StartNodeURL.
ü
Sitemap data
source control will automatically detect the sitemap file in the website and it
will the navigation configuration file without any configuration settings. We can
set the start page of the sitemap here by setting the page for StartNodeUrl
<asp:SiteMapPath id="SiteMap"
BackColor="Green"
CurrentNodeStyle-Font-Bold="true" ForeColor="Red" runat="server">
asp:SiteMapPath>
Sitemap
data source control will automatically detect the Sitemap file in the project
and it will read the file without any configuration settings. We can set the
start page of the SiteMap here by setting the page for “StartNodeUrl”.
Please
share your opinions and comments with particular topic. I will try to improve
as per your suggestion...
Thank
you very much...
Comments