当使用多个dropdownlist进行条件的判断时
可以使用一下方法
System.Text.StringBuilder sqlString=new System.Text.StringBuilder();
sqlString="select * from tableName where 1=1"
if (DropDownList1.SelectedItem.Text != "请选择") 
    sqlString.Append( " and colName1='" + DropDownList1.SelectedItem.Text + “'");
if (DropDownList2.SelectedItem.Text != "请选择") 
    sqlString.Append(" and colName2='" + DropDownList2.SelectedItem.Text + “'"); 
if(DropDownList3.SelectedItem.Text != "请选择")
sqlString.Append(" and colName3='" + DropDownList3.SelectedItem.Text + “'"); 
return sqlString;

这里1=1 表示真     也可以 2=2 等

 


 

相关文章:

  • 2022-02-07
  • 2021-12-27
  • 2022-01-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-07
  • 2021-12-05
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
  • 2021-12-29
  • 2021-08-02
相关资源
相似解决方案