<select name="age" id="age"> <option value="1=1">不限</option> <option value="age>=0 and age<=15">0-15岁</option> <option value="age>=16 and age<=22">16-22岁</option> <option value="age>=23 and age<=30">23-30岁</option> <option value="age>=31 and age<=40">31-40岁</option> <option value="age>=41">41-长生不老</option> </select>后台 string SQL = "SELECT * FROM a表 WHERE " + 这个参数;
LZ的意思是SQL怎么查询? ...where age < xx and age>xx
下拉框的value可以设置成这样0-15,16-22,23-30,31-40,40---测试数据 create table o(name varchar(10),age int) insert into o select 'aa',23 insert into o select 'bb',4 insert into o select 'cc',34 insert into o select 'dd',63 insert into o select 'ee',15 go create proc GetPeople @ages varchar(20) as select * from o where age between left(@ages,charindex('-',@ages)-1) and (case right(@ages,len(@ages)-charindex('-',@ages)) when '' then 999999999 else right(@ages,len(@ages)-charindex('-',@ages)) end) go--测试结果: exec GetPeople '0-15' exec GetPeople '40-'
或者使用二楼的思路。 查询语句直接使用:string sql="select * from 表名 where "+下拉框选定值
<option value="1=1">不限</option>
<option value="age>=0 and age<=15">0-15岁</option>
<option value="age>=16 and age<=22">16-22岁</option>
<option value="age>=23 and age<=30">23-30岁</option>
<option value="age>=31 and age<=40">31-40岁</option>
<option value="age>=41">41-长生不老</option>
</select>后台
string SQL = "SELECT * FROM a表 WHERE " + 这个参数;
create table o(name varchar(10),age int)
insert into o select 'aa',23
insert into o select 'bb',4
insert into o select 'cc',34
insert into o select 'dd',63
insert into o select 'ee',15
go
create proc GetPeople
@ages varchar(20)
as
select * from o where age between left(@ages,charindex('-',@ages)-1) and
(case right(@ages,len(@ages)-charindex('-',@ages)) when '' then 999999999 else right(@ages,len(@ages)-charindex('-',@ages)) end)
go--测试结果:
exec GetPeople '0-15'
exec GetPeople '40-'
查询语句直接使用:string sql="select * from 表名 where "+下拉框选定值
protected void Select4_ServerChange(object sender, EventArgs e)
{
string abc=this.Select4.SelectedIndex.ToString();点不出selectedvalue.tostring();
}