2个文本框的C#检查中包含数据

时间:2014-08-07 14:02:32

标签: c#

我想检查其中两个文本框中是否包含数据。如果是这样,我想做一些处理。

我有以下代码但不确定为什么即使其中一个文本框为空它也会执行:

     if (!(string.IsNullOrWhiteSpace(txtUp.Text) && (string.IsNullOrWhiteSpace(txtLower.Text)))) 
     {
        // Go here only if both textboxes have data in them

     }

2 个答案:

答案 0 :(得分:3)

您在第二个条件下缺少!。应该是:

                                              here
                                              v
if (!string.IsNullOrWhiteSpace(txtUp.Text) && !string.IsNullOrWhiteSpace(txtLower.Text)) 
{
   // Go here only if both textboxes have data in them
}

此外,括号被搞砸了

答案 1 :(得分:2)

您可以尝试这样做,即您错过了将条件放在brackets()中,因为您要检查两者,然后!

if (!((string.IsNullOrWhiteSpace(txtUp.Text) && (string.IsNullOrWhiteSpace(txtLower.Text)))))