Programmatical Custom Navigation : SiteMapDataSource « Sitemap « ASP.Net






Programmatical Custom Navigation


<%@ Page Language="C#" %>
<script runat="server">    
   void Page_Load(object sender, System.EventArgs e)
    {
        Hyperlink1.Text = SiteMap.CurrentNode.ParentNode.ToString();
        Hyperlink1.NavigateUrl = SiteMap.CurrentNode.ParentNode.Url;
        
        Hyperlink2.Text = SiteMap.CurrentNode.PreviousSibling.ToString();
        Hyperlink2.NavigateUrl = SiteMap.CurrentNode.PreviousSibling.Url;
        
        Hyperlink3.Text = SiteMap.CurrentNode.NextSibling.ToString();
        Hyperlink3.NavigateUrl = SiteMap.CurrentNode.NextSibling.Url;
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>SiteMapDataSource</title>
</head>
<body>
    <form id="form1" runat="server">
        Move Up:
        <asp:Hyperlink ID="Hyperlink1" Runat="server"></asp:Hyperlink><br />
        <-- <asp:Hyperlink ID="Hyperlink2" Runat="server"></asp:Hyperlink> | 
        <asp:Hyperlink ID="Hyperlink3" Runat="server"></asp:Hyperlink> -->        
    </form>
</body>
</html>
File: 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">
    <siteMapNode url="~/Default.aspx" title="Books">
      <siteMapNode url="~/Novels.aspx" title="Novels" />
      <siteMapNode url="~/History.aspx" title="History" />
      <siteMapNode url="~/Romance.aspx" title="Romance" />
    </siteMapNode>
    <siteMapNode url="~/Default.aspx" title="Electronics">
      <siteMapNode url="~/Cameras.aspx" title="Camera" />
      <siteMapNode url="~/Computers.aspx" title="Computer" />
    </siteMapNode>
    <siteMapNode url="~/Default.aspx" title="DVDs">
      <siteMapNode url="~/Horror.aspx" title="Horror" />
      <siteMapNode url="~/Kids.aspx" title="Kids" />
    </siteMapNode>
    <siteMapNode url="~/Default.aspx" title="Computers">
      <siteMapNode url="~/Desktop.aspx" title="Desktop" />
      <siteMapNode url="~/Laptop.aspx" title="Laptop" />
    </siteMapNode>
  </siteMapNode>
</siteMap>

 








Related examples in the same category

1.Sitemap and tree view
2.Binding a GridView with the SiteMapDataSource control
3.Simple SiteMap
4.Partial SiteMaps
5.Menu and SiteMap
6.SiteMap And MasterPage
7.Basic navigation
8.Advanced Navigation