Question

I have a asp repeater and one of the items requires me to show or hide a text string depending upon the state of TWO boolean values

This works fine:

<asp:Label ID="X" runat="server" Text="yadayada" Visible='<%# (bool)DataBinder.Eval(Container.DataItem, "field1") %>'>

Unfortunately I need to compare two fields. I'm trying to for the logic as follows:

True + True = True
True + False = False
False + True = False

So I try this:

'<%# (bool)DataBinder.Eval(Container.DataItem, "field1") + (bool)DataBinder.Eval(Container.DataItem, "field1") %>' >

I also tried placing an "if" statement before the logic to do a typical c# or (||) evaluation but the compiler won't allow the "if"

Any help would be greatly apprecieated.

Was it helpful?

Solution

You need to use && operator instead of +. Try using this:

Visible='<%# (bool)Eval("field1") && (bool)Eval("field1") %>'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top