[RESOLVED]SiteMap in ASP.Net

Hello All,

I want to create a Horizontal menu with options Home,Services,Consulting,support.

The menu should appear in horizontal and there will not be any root node or child node all node will be on single horizontal level.

How to write sitemap code for it ?

Such as :

Home    Services    Consulting   Support

 

Thanks in Advance,

Praneet

Hi,

You can use the below sitemap to create horizontal menu. Chane url as per your design

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
  <siteMapNode url="" title="RootNode" description="RootNode" roles="*">
    <siteMapNode url="~/Home.aspx" title="Home"  />
    <siteMapNode url="~/Services.aspx" title="Services"   />
    <siteMapNode url="~/Consulting.aspx" title="Consulting"  />
    <siteMapNode url="~/Support.aspx" title="Support" />
  </siteMapNode>
</siteMap>

You need to have a root node in your site map. so to remove the Root node you need to set the sitemap datasource
ShowStartingNode property to false

 <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server"  ShowStartingNode="false" />

To make the Menu display as Horizontal you need to set the orientation of menu to be ‘Horizontal’

  <asp:Menu ID="Menu1" runat="server" Orientation="Horizontal" StaticDisplayLevels="1" DataSourceID="SiteMapDataSource1" >
        </asp:Menu>

Complete Code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Menu ID="Menu1" runat="server" Orientation="Horizontal" StaticDisplayLevels="1" DataSourceID="SiteMapDataSource1" >
        </asp:Menu>
        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server"  ShowStartingNode="false" />
    </div>
    </form>
</body>
</html>

Leave a Reply