Performing Eval on XML DataSource for Menu Rollovers

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:

wayneph
12-01-2006, 07:15 AM
i played around a while back with setting something like this up. If I recall correctly, I ended up using the ItemDataBound event in the Code Behind. At that point I compared the Current URL to the URL in the Item and changed the CSSClass of my object that way.

Unfortunately, I don't have any of the code handy, so I can't go back and check.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum