.net dropdownlist绑定的问题

来源:百度知道 编辑:UC知道 时间:2024/06/20 00:05:19
我4个dropdownlist已从数据库中绑定数据,按条件进行查询时除了要用
例如
if(dropdownlist1==1&&dropdownlist2=2)
{}
if(dropdownlist1==1)
{}
if(dropdownlist2==2)
{}
这种分别写出每一种查询的条件外,还有其它的方法吗?
4个dropdownlist分别是按行业,职位,地点,时间搜索,不是要分清每一种情况,像
if(dropdownlist1==计算机&&dropdownlist2==不限&&dropdownlist3==不限&&dropdownlist4==一周内)
{}
if(dropdownlist1==产限&&dropdownlist2==不限&&dropdownlist3==北京&&dropdownlist4==一周内)
{}
.
.
.
要分别列出每一种搜索的可能性,4个dropdownlist要列出十几种选择的情况,现在已经可以查询,只是写出来的代码太麻烦,想问下有没有其它好一点的方法?

用like就行,
首先
string a=dropdownlist1.selectedItems.text
string b=dropdownlist2.selectedItems.text
string c=dropdownlist3.selectedItems.text
string d=dropdownlist4.selectedItems.text
if(a=="不限")
a=null;
if(b=="不限")
b=null;
if(c=="不限")
c=null;
if(d=="不限")
d=null;
然后写SQL文:
select * from tabel t where 行业 like '%"+a+"%' and 职位 like '%"+b+"%' and 地点 like '%"+c+"%'and 时间 like '%"+d+"%'

数据库肯定也有行业 职位 地点 时间的字段
直接
写SQL 比如
select * from table1 where 行业 like ‘%“+dropdownlist1+”%’and 地点 like ............

select * from tabel t where 行业 like '%"+a+"%' and 职位 like '%"+b+"%' and 地点 like '%"+c+"%'and 时间 like '%"+d+"%'

不好吧