我试图要求用户在运行搜索查询之前至少在五个文本框之一中输入数据。 .
我收到关于
的错误信息将字符串转换为 bool 值 2 “运算符 '&&' 不能应用于 'string' 和 'string' 类型的操作数”
if (txtLoginName.Text=String.Empty && txtDisplayName.Text = String.Empty && txtCode.Text = String.Empty && txtEmailAddress.Text = String.Empty && txtName.Text = String.Empty) { lblErrorMessage.Text = "At least one search criteria is required."; return; }
最佳答案
试试下面的代码。在您的示例中,您在 C# 中使用“=”而不是“==”。
if (txtLoginName.Text==String.Empty &&
txtDisplayName.Text == String.Empty &&
txtCode.Text == String.Empty &&
txtEmailAddress.Text == String.Empty &&
txtName.Text == String.Empty)
完成同样事情的另一种方法是使用这个:
if (!String.IsNullorEmpty(txtLoginName.Text) &&
!String.IsNullorEmpty(txtDisplayName.Text) &&
!String.IsNullorEmpty(txtCode.Text) &&
!String.IsNullorEmpty(txtEmailAddress.Text) &&
!String.IsNullorEmpty(txtName.Text))
关于c# - 要求搜索页面上至少一个文本框中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1335357/