想请你帮忙。我对 asp.net 2.0 中的声明性语句有点迷失。
当当前路径等于我提供的路径时,我想为 A 标记添加特定类“selected”或“noselected”。我尝试过,但它不起作用。代码如下:
" class="<%# (DataBinder.Eval(Container.DataItem, "Url").ToString().Equals(Request.RawUrl))?"selected":"notselected" %>">链接名称 ;
“Url”的值是“/SubDir/SecondPage.aspx”
我不确定简短的“IF”语句是否有效以及我是否比较正确的 url 值。
如果你们看到一些有意义的事情,那就太好了。
谢谢。 X.
[编辑] 好的,上面的代码完全没问题,无需更改。问题出在我身上,打败我。
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.
发布评论
评论(1)
这个概念看起来不错。您可能想对 URL 字符串值和 RawUrl 尝试
ToLower()
。The concept looks fine. You might want to try
ToLower()
on both the URL string value and the RawUrl.