Geeks With Blogs

AzamSharp Some day I will know everything. I hope that day never comes.

ASP.NET 2.0 provides a great feature of creating Bread Crumbs. Bread Crumbs appears as links or images and shows the user his current position in the website. This means if you are in horror books section under books so you can see a link something like:

Home -> Books -> Horror Books

Creating the Bread Crumbs is also very easy. All you need to do is to set up your Web.sitemap file correctly and use the SiteMapPath control to display the Bread Crumbs. It is wise to use the SiteMapPath control in a master page so that you can display the path in all the pages that inherit from the master page.

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="">
    <siteMapNode url="~/Books/Default.aspx" title="Books"  description="">
      <siteMapNode url="~/Books/RomanceBooks.aspx" title="Romance Books" />
      <siteMapNode url="~/Books/HorrorBooks.aspx" title="Horror Books" />   
    </siteMapNode>

    <siteMapNode url="~/Movies/Default.aspx" title="Movies">    
     
    </siteMapNode>
   
   
    </siteMapNode>
</siteMap>

Master Page:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="Site" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
               
          <asp:SiteMapPath ID="SiteMapPath1" runat="server">
         
          <RootNodeTemplate>
         
          <asp:HyperLink ID="HyperLink1" runat="server"
          Text='<%# Eval("title") %>' NavigateUrl='<%# Eval("url") %>' />
         
          </RootNodeTemplate>
                   
          <NodeTemplate>
            <asp:HyperLink ID="HyperLink2" runat="server"
            Text='<%# Eval("title") %>' NavigateUrl='<%# Eval("url") %>' />
          </NodeTemplate>
         
          </asp:SiteMapPath>
               
        </asp:contentplaceholder>
       
        <asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
       
        </asp:ContentPlaceHolder>
       
       
       
    </div>
    </form>
</body>
</html>

And that is pretty much it. Now, you will see a Bread Crumb displayed on your ASP.NET pages that inherit from the master page.

powered by IMHO 1.3

Posted on Wednesday, August 16, 2006 10:07 PM | Back to top


Comments on this post: Bread Crumbs in ASP.NET 2.0

# re: Bread Crumbs in ASP.NET 2.0
Requesting Gravatar...
hi
what if i m not using Master PAges then how can i use breadcrumbs and site map
Left by daman on Sep 21, 2006 1:34 AM

# re: Bread Crumbs in ASP.NET 2.0
Requesting Gravatar...
how to do multi language breag crumbs
Left by suyog on Feb 18, 2008 1:47 AM

# re: Bread Crumbs in ASP.NET 2.0
Requesting Gravatar...
Hi,
Good and helpful post. but i get only 2 breadcrumbs how much ever i navigate!! Can u tell where i went wrong?
Left by Aparna on Nov 15, 2010 4:58 PM

Your comment:
 (will show your gravatar)


Copyright © Mohammad Azam | Powered by: GeeksWithBlogs.net