Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为单个布尔结果计算两个布尔_C#_Asp.net_Boolean_Repeater_Databinder - Fatal编程技术网

C# 为单个布尔结果计算两个布尔

C# 为单个布尔结果计算两个布尔,c#,asp.net,boolean,repeater,databinder,C#,Asp.net,Boolean,Repeater,Databinder,我有一个asp中继器,其中一项要求我根据两个布尔值的状态显示或隐藏文本字符串 这很好: <asp:Label ID="X" runat="server" Text="yadayada" Visible='<%# (bool)DataBinder.Eval(Container.DataItem, "field1") %>'> 所以我试着这样做: '<%# (bool)DataBinder.Eval(Container.DataItem, "field1") + (b

我有一个asp中继器,其中一项要求我根据两个布尔值的状态显示或隐藏文本字符串

这很好:

<asp:Label ID="X" runat="server" Text="yadayada" Visible='<%# (bool)DataBinder.Eval(Container.DataItem, "field1") %>'>
所以我试着这样做:

'<%# (bool)DataBinder.Eval(Container.DataItem, "field1") + (bool)DataBinder.Eval(Container.DataItem, "field1") %>' >
“”>
我还尝试在逻辑之前放置一个
“if”
语句,以执行典型的
c
(| |)
求值,但编译器不允许使用
“if”


任何帮助都将非常感谢。

您需要使用
&&
操作符,而不是
+
。尝试使用以下方法:

Visible='<%# (bool)Eval("field1") && (bool)Eval("field1") %>'
Visible=''

使用
&&
而不是
+
看起来像你想要的那样:两个true都是true,其他任何东西都是false。尝试
&&
而不是
|
+
。&&code>工作正常。谢谢大家。如果对两个操作数都进行了计算,
&&
将为您提供
true
。这不是你想要的吗?如果两个操作数都是
false
,是否要
true
?您建议的答案似乎非常有效。谢谢
Visible='<%# (bool)Eval("field1") && (bool)Eval("field1") %>'