Wednesday, 25 December 2013

Binding Sitemap file to Menu Control in ASP.NET

In this article we are going to see how to bind a sitemap file to the menu control, For  that we have to create a site map file and map all the URL with display name to the web.sitemap file. Next drag and drop the SiteMapDataSource to the master page. Mention the ShowStartingNode as False in SiteMapDataSource. For xmldatasource we have to specify the databindings in menu control, but for the sitemapdatasource it is not needed.

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="" >
    <siteMapNode title="Root">
      <siteMapNode url="~/Homes.aspx" title="Home" />
      <siteMapNode url="~/Employee.aspx" title="Employee">
        <siteMapNode url="~/AddEmployee.aspx"   title="Add Employee"></siteMapNode>
      <siteMapNode url="~/Adm.aspx" title="Admin">
        <siteMapNode url="~/AddUser.aspx" title="Add User"/>


  <form id="form1" runat="server">
        <asp:SiteMapPath ID="SiteMapPath1" runat="server"
    <br />
    <div style="padding:10px">
    <asp:Menu DataSourceID="SiteMapDataSource1"  StaticMenuItemStyle-ItemSpacing="30px" DisappearAfter="2000"   runat="server" Orientation="Horizontal">
        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server"  ShowStartingNode="false" />

        <asp:ContentPlaceHolder ID="ContentPlaceHolder1"  runat="server">                       

Output :

From this article you can learn how to bind the SiteMap file to the Menu control.

No comments:

Post a Comment