简体   繁体   English

为什么这对我不起作用? 它总是返回TRUE

[英]why does this NOT work for me? it always returns TRUE

I have been pulling my hair out trying to figure out why this seems to work for others but not me. 我一直在拔头发,试图弄清为什么这似乎对其他人有用,但对我却无效。

I have some data and in the Hours2 column there are clearly cells with NULL and some with hours like this 我有一些数据,并且在Hours2列中显然有带有NULL的单元格,而有些具有这样的小时数

'9:00 a.m. - 6:00 p.m.'
NULL
NULL
'9:00 a.m. - 6:00 p.m.'
'9:00 a.m. - 5:00 p.m.'
NULL
NULL
NULL

yet I can't figure out how to do what seems like if should be a simple IF statement with some inline code. 但是我不知道应该怎么做,如果应该是带有一些内联代码的简单IF语句。 I already use 我已经用过

<%# Eval("Hours2") %> to get the values and that shows up fine... <%# Eval("Hours2") %>来获取值,并且显示得很好...

IN the first case I want to display one or the other bit of text if Hours2 is NULL or not. 在第一种情况下,如果Hours2为NULL,我想显示一个或另一段文本。 (this is the label text for my hours one data, if there is Hours2 then Friday has a different time) (这是我的一个小时的数据的标签文本,如果有Hours2,则Friday具有不同的时间)

<%# Eval("Hours2") != DBNull.Value ? "mon - thurs" : "mon - fri" %>

This based on answers from other on other things here at Stack sounds like it should work, but it's ALWAYS TRUE... 这是基于Stack上其他问题的答案,听起来应该可行,但这始终是正确的...

same thing if i'm trying to just use True or False to make things Visible or not... 如果我试图仅使用True或False来使事物可见或不可见,则同样的事情...

Visible ='<%# Eval("Hours2") != DBNull.Value %>'

I'm clearly missing some thing here...!!! 我显然在这里错过了一些东西... !!!

Move the logic to the codehind: 将逻辑移至代码隐藏:

<%# GetString(Eval("Hours2")) %>

Then use your debugger to figure out what is actually being passed. 然后使用调试器找出实际传递的内容。

public string GetString(object hours){
 ...
}

try this: 尝试这个:

Visible ='<%# Eval("Hours2").ToString() != "" %>'

or 要么

Visible ='<%# !String.IsNullOrEmpty(Eval("Hours2").ToString()) %>'

您可以尝试以其他方式检查它...这就是我可能要做的。

<%#(String.IsNullOrEmpty(Eval("Hours2").ToString()) ? "mon-thurs" : "mon-fri")%>

how you can get it from SQL. 如何从SQL获取它。 Means using LINQ or call SP? 是指使用LINQ还是致电SP? You can use isnull(Hours2,0) Hours2 or isnull(Hours2,'') Hours2 in your Query. 您可以在查询中使用isull(hours2,0)Hours2或isull(Hours2,'')Hours2。 and it will work for you like this. 这样它将对您有效。

<%# Eval("Hours2") != 0 ? "mon - thurs" : "mon - fri" %>

OR 要么

<%# Eval("Hours2") != '' ? "mon - thurs" : "mon - fri" %>

OR 要么

<%# !String.IsNullOrEmpty(Eval("Hours2").ToString()) ? "mon - thurs" : "mon - fri" %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM