asp.net 多重条件查询语句
protected void ImageSelect_Click(object sender, ImageClickEventArgs e)
{
where.Text = "";
string contion = " where 1=1 ";//使用一个真条件,后面跟上搜索的条件,条件是否为空,都可以执行
if (Text1.Text.Trim() != "")
{
contion = contion + "and Text1 like '%" + Text1.Text.Trim() + "%'";
}
if (Text2.Text.Trim() != "")
{
contion = contion + "and Text2 like '%" + Text2.Text.Trim() + "%'";
}
if (Text3.Text.Trim() != "")
{
contion = contion + "and Text3 like '%" + Text3 .Text.Trim() + "%'";
}
if (DropDownList1.SelectedValue != "")
{
contion = contion + "and DropDownList1like '" + DropDownList1.SelectedValue + "%'";
}
where.Text = contion;
select(); //查询方法
}