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="Forside" description="">
<siteMapNode url="~/test1.aspx" title="Test1" description="" >
<siteMapNode url="~/test2.aspx" title="Test2" description="" >
<siteMapNode url="~/test3.aspx" title="Test3" description="" >
<siteMapNode url="~/test4.aspx" title="Test4" description="" />
</siteMapNode>
</siteMapNode>
</siteMapNode>
</siteMapNode>
</siteMap>
AppMaster.master
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="AppMaster.master.cs" Inherits="AppMaster" %>
<!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" lang="da" xml:lang="da">
<head runat="server">
<title>TITLE</title>
<!--[if IE 5]>
<style type="text/css">
.sidebarcontainer td, .sidebarcontainer tr {font-size:smaller;}
#subnav a {height:1em;}
body td, body th {font-size:0.78em;}
</style>
<![endif]-->
<!--[if IE 7]>
<style type="text/css">
#rightcolumn{margin-right: -152px;}
</style>
<![endif]-->
</head>
<body>
<form id="mainForm" runat="server">
<div id="wrapper">
<div id="mainnav">
<asp:SiteMapDataSource runat="server" ID="sitemap" />
<asp:Menu DataSourceID="sitemap" ID="mainmenu" SkinID="mainmenu" runat="server" OnMenuItemDataBound="MainMenu_MenuItemDataBound" Width="10px" />
</div>
<div id="subnav1">
<asp:SiteMapDataSource ID="subnav1SiteMap" runat="server" ShowStartingNode="False" StartingNodeOffset="1" />
<asp:Menu DataSourceID="subnav1SiteMap" ID="subMenu1" runat="server" Orientation="Horizontal" SkinID="subMenu1" />
</div>
<div id="headerimg">
<table border="0">
<tr>
<td>
<img src="main_page_teaser_left.gif" align="top" /><img src="baggrund.bmp" align="top" />
</td>
</tr>
</table></div>
<div id="header">
<asp:ContentPlaceHolder runat="server" ID="top">
</asp:ContentPlaceHolder>
</div>
<div id="contentwrapper">
<div id="floatwrapper">
<!-- brødkrumme -->
<div id="centercolumn">
<div id="breadcrumbs">
<asp:SiteMapPath runat="server" ID="smPath" />
</div>
<!-- indholdsrude -->
<div id="copy">
<asp:ContentPlaceHolder runat="server" ID="mainCopy">
<%-- Main page content goes here. Create a single
content box by wrapping everything in one
<div class="container"> or create multiple boxes
as needed. See the sample homepage for a
demonstration.
This is the general structure:
<div class="container">
<h1>Headline</h1>
<p class="teaser">Teaser text</p>
<p>Regular text and other markup.</p>
</div>
--%>
</asp:ContentPlaceHolder>
</div>
</div>
<!-- venstre kolonne -->
<div id="leftcolumn">
<div id="leftcolcontainer">
<div id="subnav">
<asp:SiteMapDataSource runat="server" ID="subnavSitemap" StartingNodeOffset="2" ShowStartingNode="False" />
<asp:Menu runat="server" ID="subMenu" SkinID="subMenu" DataSourceID="subnavSitemap" />
</div>
<asp:ContentPlaceHolder ID="leftColumn" runat="server" Visible="true">
<%-- Left sidebar content placeholder. Again the
individual boxes are created by using a <div> and
assigning a class to it: 'sidebarcontainer'.
Follow the structure of the sample content below:
<div class="sidebarcontainer">
<h4>Headline</h4>
<p>Content</p>
</div>
--%>
<!--div class="sidebarcontainer">
<%-- Kontrol eller lign. --%>
</div-->
</asp:ContentPlaceHolder>
</div>
</div>
</div>
<!-- højre kolonne -->
<div id="rightcolumn">
<div id="rightcolcontainer">
<asp:ContentPlaceHolder ID="rightColumn" runat="server">
<%-- Right sidebar content placeholder. Again the
individual boxes are created by using a <div> and
assigning a class to it: 'sidebarcontainer'.
Follow the structure of the sample content below:
<div class="sidebarcontainer">
<h4>Headline</h4>
<p>Content</p>
</div>
--%>
<div class="sidebarcontainer">
<h3>Nyheder</h3>
<b>10. januar 2007</b><br />
tekst...<br />
<img src="images/link-arrow-dbl-red.gif" /> <span style="color:#C30F10;">Læs mere</span>
<br /><br />
<b>12. januar 2007</b><br />
tekst...<br />
<img src="images/link-arrow-dbl-red.gif" /> <span style="color:#C30F10;">Læs mere</span>
<br /><br />
<b>16. januar 2007</b><br />
tekst...<br />
<img src="images/link-arrow-dbl-red.gif" /> <span style="color:#C30F10;">Læs mere</span>
</div>
</asp:ContentPlaceHolder>
</div>
</div>
<!-- bund (under indholdsrude) -->
<div id="footer">
© Alle rettigheder forbeholdes.
</div>
</div>
</div>
</form>
</body>
</html>
AppMaster.master (Codebehind):
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class AppMaster : System.Web.UI.MasterPage
{
/// <summary>
/// Event handler that highlights the top level menu section for all
/// sections and pages below it.
/// </summary>
protected void MainMenu_MenuItemDataBound(Object sender, MenuEventArgs e)
{
if (mainmenu.SelectedItem == null)
{
if (IsNodeAncestor((SiteMapNode)e.Item.DataItem, SiteMap.CurrentNode))
e.Item.Selected = true;
}
}
/// <summary>
/// Determines if a <see cref="System.Web.SiteMapNode"/> is the ancestor of a second one.
/// </summary>
/// <param name="ancestor">The <see cref="System.Web.SiteMapNode"/> in question.</param>
/// <param name="child">A <see cref="System.Web.SiteMapNode"/> which may or may not be
/// the <paramref name="ancestor"/>'s child.</param>
/// <returns><c>true</c>, if the two nodes are related, <c>false</c> otherwise.</returns>
private bool IsNodeAncestor(SiteMapNode ancestor, SiteMapNode child)
{
bool result = false;
if (ancestor.ChildNodes != null && ancestor.ChildNodes.Contains(child))
return true;
else
{
if (child.ParentNode != null && ancestor != child.RootNode)
{
return IsNodeAncestor(ancestor, child.ParentNode);
}
}
return result;
}
}