c# - 要求搜索页面上至少一个文本框中的数据

标签 c# asp.net

我试图要求用户在运行搜索查询之前至少在五个文本框之一中输入数据。 .

我收到关于

的错误信息
  1. 将字符串转换为 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/

相关文章:

c# - 是否有示例说明为什么应在 NHibernate 中覆盖 Equals/GetHashCode?

c# - 在运行时加载模块化 ASP.NET 组件

c# - 在水平布局中动态添加控件到面板

javascript - Asp.net/Javascript 在选中复选框时删除输入字段的值

c# - 如何以编程方式调用 C++ 编译器?

c# - 如何对 ViewModel 消费方法进行单元测试?

c# - 基础连接已关闭。无法使用 HTTP.sys 运行 Asp.Net Core 2.1 Web API 应用程序?

Jquery 表单验证/Asp MVC 模型绑定(bind) - 名称中包含句点

c# - WPF 图像仅在时间跨度完成后更新

c# - 检查SQL成功