techsupportpete
11-30-2006, 03:13 PM
Hi
I have a simple asp.net menu being created using a repeater from an xml sitemap.
This is located in my site.master.
Now, I am formatting the menu styles using css, and this perfoms simple roll over operation with some colour changing.
When I click on a menu item it takes me to a page. What I want is for the repeater to detect the current page and for that page in the menu change its css style to say 'selected'
This is my code:
<asp:SiteMapDataSource ID="SiteMapDataSource" ShowStartingNode="false" runat="server" />
<ul>
<asp:Repeater ID="menu_repeater" DataSourceID="SiteMapDataSource" runat="server">
<ItemTemplate>
<li>
<a href='<%#Eval("url") %>'
'<%
string sURL = Request.Url.ToString().ToLower();
if (sURL.Contains(Eval("url").ToString() ) ){%> 'class='selected' '<%} %>'>
<%#Eval("Title") %></a>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
If I remvoe the code in the middle of the code above starting with <% string sURL then it all works but i cant show the selected menu tab.
Im pretty sure Im getting the page title correctly, but an error fires up saying that "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control"
Any ideas what I can do to resolve this?
Any help would be great thanks!
Pete
:confused:
I have a simple asp.net menu being created using a repeater from an xml sitemap.
This is located in my site.master.
Now, I am formatting the menu styles using css, and this perfoms simple roll over operation with some colour changing.
When I click on a menu item it takes me to a page. What I want is for the repeater to detect the current page and for that page in the menu change its css style to say 'selected'
This is my code:
<asp:SiteMapDataSource ID="SiteMapDataSource" ShowStartingNode="false" runat="server" />
<ul>
<asp:Repeater ID="menu_repeater" DataSourceID="SiteMapDataSource" runat="server">
<ItemTemplate>
<li>
<a href='<%#Eval("url") %>'
'<%
string sURL = Request.Url.ToString().ToLower();
if (sURL.Contains(Eval("url").ToString() ) ){%> 'class='selected' '<%} %>'>
<%#Eval("Title") %></a>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
If I remvoe the code in the middle of the code above starting with <% string sURL then it all works but i cant show the selected menu tab.
Im pretty sure Im getting the page title correctly, but an error fires up saying that "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control"
Any ideas what I can do to resolve this?
Any help would be great thanks!
Pete
:confused: