Asp.net SiteMap & Breadcrumb

mybwu_com發表於2014-01-06

Site Map & Breadcrumb

Flow:

Site Map Data sourceUsage:

Step 1:Prepare Site Map xml

Add it toWeb site root path.

Xml:

<siteMapxmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
 
  <siteMapNode title="Home"description="Home" url="./default.aspx">
    <siteMapNode title="Products"description="Our products" url="./Products.aspx">
      <siteMapNodetitle="Hardware" description="Hardware choices"url="./Hardware.aspx" />
      <siteMapNodetitle="Software" description="Software choices"url="./Software.aspx" />
    </siteMapNode>
    <siteMapNode title="Services"description="Services we offer" url="./Services.aspx">
      <siteMapNodetitle="Training" description="Training classes" url="./Training.aspx"/>
      <siteMapNodetitle="Consulting" description="Consulting services"url="./Consulting.aspx" />
      <siteMapNode title="Support"description="Support plans" url="./Support.aspx" />
    </siteMapNode>
  </siteMapNode>
</siteMap>


Step 2:Prepare master page

Step 3: AddSite map Data source

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


Step 4: Addmenu control, point to site map data source

 <div style="margin-top:100px;margin-bottom: 100px;">
           
            <asp:Menu ID="Menu1"runat="server" DataSourceID="smdsTest"Orientation="Horizontal">
        </asp:Menu>
 </div>


Breadcrumb:

<div>
        <asp:SiteMapPath  runat="server"ID="SiteMapPath1">
            <PathSeparatorTemplate>
                <span>-></span>
            </PathSeparatorTemplate>
            <RootNodeTemplate>
                <span>Home</span>
            </RootNodeTemplate>
            <CurrentNodeTemplate>
                <i>
                    <asp:LabelID="Label1" runat="server" Text='<%#Eval("title") %>'>
                    </asp:Label>
                </i>
            </CurrentNodeTemplate>
        </asp:SiteMapPath>
    </div>


相關文章