I have a control with the visible property set to the value of a boolean field. However, I want the visiblity to be the opposite of the boolean field. How do I do this?

This code shows the visible property set to the value of the field. I want to negate that value.

<span runat="server" id="toMonthYear" visible='<%#Eval("isAttending")%>'>
     <%#Eval("toMonthName")%> 
</span>
有帮助吗?

解决方案

Simply cast it to bool and use the negation operator (NOT in VB.NET).

Visible='<%# !(bool)Eval("isAttending") %>'

其他提示

Try this

<span runat="server" id="toMonthYear" visible='<%#(!Boolean.Parse(Eval("isAttending"))%>'>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top