Bread Crumbs is a new Site Navigation feature in ASP.NET 2.0, which can make building navigation structures across a web site much easier and simpler. It’s very easy to create Bread Crumbs with ASP.Net 2.0. Breadcrumbs are links that shows the user his/her current position in the website. This is the path from the root of the website, to the one you are currently looking at.
Example:
Home > Knowledge > Tips > ASP.Net > Creating Bread Crumbs with ASP.Net
Sample Code:
# Create a web site.
# Add a new file to the solution called Web.sitemap – A file used to create a site map.
# Add the following code to the Web.sitemap file.
Listing 1 :
<?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="This is my home page."> <siteMapNode url="Knowledge.aspx" title="Knowledge" description="This is my Knowledge page."> <siteMapNode url="Tips.aspx" title="Tips" description="Tips section" > <siteMapNode url="Aspnet.aspx" title="ASP.Net" description="ASP.Net section" > <siteMapNode url="Breadcrumbs.aspx" title="Creating Bread Crumbs with ASP.Net" description="Creating Bread Crumbs with ASP.Net" /> </siteMapNode> <siteMapNode url="js.aspx" title="Java Script" description="Java Script Section" /> </siteMapNode> <siteMapNode url="Articles.aspx" title="Articles" description="Articles Section" /> </siteMapNode> <siteMapNode url="Goal.aspx" title="Goal" description="Goal section" /> <siteMapNode url="People.aspx" title="People" description="People Section" /> </siteMapNode> </siteMap>
Listing 2 :
Then in each node page you need to place the following code. Or else you can use the SiteMapPath control in the master page so that you can display the path in all the pages that inherit from the master page instead of adding in each page.
<div> <asp:SiteMapPath ID="SiteMapPath1" runat="server"> </asp:SiteMapPath> </div>
Now run the web site and on click of any of the links , you can move to the desired page easily. This is a very basic sample of Bread crumb navigation implementation.