0

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.

mshsayem
  • 17,557
  • 11
  • 61
  • 69
T3.0
  • 446
  • 1
  • 6
  • 21

1 Answers1

2

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

Visible='<%# (bool)Eval("field1") && (bool)Eval("field1") %>'
mshsayem
  • 17,557
  • 11
  • 61
  • 69
  • Well, `&&` will give you `true` if both of the operands are evaluated `true`. Isn't it what you want? Do you want `true` if both operands are `false`? – mshsayem Jun 19 '13 at 01:29
  • Your suggested answer seems to be working great mshsayem. Thanks. – T3.0 Jun 19 '13 at 04:28