Question

wanna ask you for help. I am bit lost with declarative statement in asp.net 2.0.
I want add specific class "selected" or "noselected" for A tag when current path is equal to path I provide. I tried st., but it is not working. The code is below:
<a href="<%# DataBinder.Eval(Container.DataItem, "Url") %>" class="<%# (DataBinder.Eval(Container.DataItem, "Url").ToString().Equals(Request.RawUrl))?"selected":"notselected" %>">linkname</a>

the value of "Url" is "/SubDir/SecondPage.aspx"

I am not sure if short "IF" statment works and if I compare right values of urls. If you see guys something significant, would be great.

Thanks. X.

[EDIT] OK, the code above is completely fine, no need to change it. the problem was in me.Beat me.

Was it helpful?

Solution

The concept looks fine. You might want to try ToLower() on both the URL string value and the RawUrl.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top