I am having some trouble with some K# syntax within a transformation.
I have a document type that has a Boolean check box field. I want to be able to use this field in a conditional statement to decide a class name.
currently I have:
<li class="{% Eval("isFeatured").toLower() == "true" ? "isFeatured" : "" %}">
the part that is seeming to not work is the area between {% %}. it is rendering out in the DOM as:
<li class="{% Eval(" isfeatured").tolower()="=" "true"="" ?="" "isfeatured"="" :="" ""="" |(user)administrator|(hash)498f3f53b6cf5d97668230efbdd569fc51cdf3702d5e097e37e0de0867f3faf1%}"="">
any help on this would be appreciated.
thanks in advance.
the li tags should render with a class name of either "isFeatured" or ""
sorry the editor took my tags and markup.
Are you using ASCX transformation or some other text type of transformation? If its not ASCX, then Eval("ColumnName") will not work. I believe you have to use GetValue("ColumnName").ToBool() for the text transformations although I don't use them very often if at all.
Eval("ColumnName")
GetValue("ColumnName").ToBool()
As Brenden said no Eval() needed in Text/XML. You can do the test on a bool like:
{%isFeatured == true ? "isFeatured" : ""%}
I was using the ASCX.
what would be the best practice to do this type of conditional operation?
I found a reference guide that showed me methods that could be used. here is the link.
I also switched my code to <li class="<%# IfTrue(Eval("isFeatured"), "featured")%>"> this worked for me
<li class="<%# IfTrue(Eval("isFeatured"), "featured")%>">
Please, sign in to be able to submit a new answer.