What I want to do is something like this:

<asp:Label ID="titleLabel" runat="server" 
        **Text='<%# SiteMap.CurrentNode.Title %>'**></asp:Label>

Where I can bind the name of the current page node in the Site Map to the title label on that page. We are doing this because, until we get these names finalized, they may change often. The above code does not work, at least for me; it displays nothing.

Any ideas are appreciated.

EDIT: Obviously I could do this in the code behind (i.e. Page Load event or something similar) but I would really rather do it in the aspx code.

+1  A: 

Its been a while but I believe its <%= #Eval(SiteMap.CurrentNode.Title) %>


Text='<%= SiteMap.CurrentNode.Title%>'

Hopefully that works the same as it would

<%= SiteMap.CurrentNode.Title%>


David Yancey
This seems to give me the same result as before: nothing displayed.
Matthew Jones
Take out the #Eval. See Edit.
David Yancey
Sorry. Same result as before. Thanks for the help, though.
Matthew Jones

As an alternative to using a label, you could also use the SiteMapPath control and hide the parent nodes:

<asp:SiteMapPath ID="SiteMapPath1" runat="server" ParentLevelsDisplayed="0">

The property ParentLevelsDisplayed allows you to specify how many parent nodes of the current sitemap node you want to display.

This works, but would prefer to bind to a label or literal. Will mark your answer as correct if no one comes up with the solution for a label/literal by the end of the week.
Matthew Jones
+1  A: 

It does work with

<span><%= SiteMap.CurrentNode.Title %></span>

which is the same output as asp:Label

Johan Leino
Works like a charm! Thanks!
Matthew Jones
Nice work Johan
David Yancey