SiteMapPath control Tutorial with example in ASP.Net

Theo: nguyenhaidang.name.vn | 05/08/2016 - 01:59

 In this article I will explain a tutorial with an example, how to use the SiteMapPath control in ASP.Net.

The SiteMapPath control is used for displaying paths of pages dynamically from the SiteMap file using the SiteMapDataSource control.
 
 
HTML Markup
Below is the HTML Markup of the Master Page Main.Master that contains the SiteMapPath control as well as the SiteMapDataSource control.
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="true" />
<asp:SiteMapPath ID="SiteMapPath1" runat="server" PathSeparator=" > " RenderCurrentNodeAsLink="false">
</asp:SiteMapPath>
<hr />
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
 
 
Adding the Sitemap XML and understanding its use
Sitemap is nothing but a map of your site, it is an XML file which has all the Pages and the Child Pages present in the site. Whenever a new page has to be added to your site, you simply need to add its node in the sitemap XML file and the ASP.Net SiteMapDataSource control will automatically grab and display it.
Sitemap can be added using Add New Item Dialog of Visual Studio as shown below.

SiteMapPath control Tutorial with example in ASP.Net

 
Once the file is added you need to structure it based on the Level 1 Pages and the Child Pages.
Below is the sitemap I am using for this article, it has the following page structure.
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
 <siteMapNode url="Home.aspx" title="Home" description="Home Page" >
    <siteMapNode url="Services.aspx" title="Services" description="Services Page">
      <siteMapNode url ="Consulting.aspx" title="Consulting" description="Consulting Page"></siteMapNode>
      <siteMapNode url ="Outsourcing.aspx" title="Outsourcing" description="Outsourcing Page"></siteMapNode>
    </siteMapNode>
    <siteMapNode url="About.aspx" title="About" description="About Us Page" />
    <siteMapNode url="Contact.aspx" title="Contact" description="Contact Us Page" />
 </siteMapNode>
</siteMap>
 
Demo: 
 
From: http://www.aspsnippets.com/
Back Head Print
Tin khác

Search GridView with Paging on TextBox KeyPress using jQuery in ASP.Net    (28/07/2010)

Bootstrap AutoComplete TextBox example using jQuery TypeAhead plugin in ASP.Net with C# and VB.Net    (28/07/2010)

Disable Button and Submit button after one click using JavaScript and jQuery    (29/07/2010)

Split and convert Comma Separated (Delimited) String to Table in SQL Server    (01/09/2010)

Select Column values as Comma Separated (Delimited) string in SQL Server using COALESCE    (01/09/2010)