在Asp.Net C#我有四个下拉列表,我想搜索他们选择的项目。条件如下框所示。救命!! [英] In Asp.Net C# I Have Four Dropdownlist And I Want To Search On Their Selected Item. The Condition Is As Posted In Below Box. Help!!
问题描述
我有四个下拉列表,我想在按钮点击时搜索他们选择的项目。什么写在查询字符串的条件??
我想要的条件是:
1.如果四个中的任何一个被选中而其他三个未被选中搜索根据1个选定的项目发生
2.如果选择了其中两个中的任何一个而未选择其他两个,则根据该2个选定项目进行搜索
3.如果选择四个中的三个而未选择其中一个根据该3个选定项目进行搜索
4.如果所有四个都被选中,则基于该4个所选项目进行搜索。
非常感谢您的帮助!
I have four dropdownlist and i want to search on their selected item on button click. what to write in where condition of query string ??
the condition i want is :
1. if either one of the four is selected and other three are not selected search happens based on that 1 selected items
2. if either two of the four is selected and other two are not selected search happens based on that 2 selected items
3. if either three of the four is selected and other one is not selected search happens based on that 3 selected items
4. if all of the four is selected search happens based on that 4 selected items.
Will appreciate your help!
推荐答案
使用按钮单击下面的代码活动
Use Below code in the button click event
try
{
DataSet Ds = new DataSet();
string category = "";
if (DropDownList1.SelectedIndex > 0)
{
category = "cat = '" + DropDownList1.SelectedItem.Text + "' AND";
}
else
{
category = "";
}
string sql = "";
if (DropDownList2.SelectedIndex > 0)
{
sql = sql + "subcat='" + DropDownList2.SelectedItem.Text + "' and ";
}
if (DropDownList3.SelectedIndex > 0)
{
sql = sql + "type='" + DropDownList3.SelectedItem.Text + "' and ";
}
if (DropDownList4.SelectedIndex > 0)
{
sql = sql + "cat='" + DropDownList4.SelectedItem.Text + "' and ";
}
sql = "SELECT * FROM tb_products where " + category + " " + sql + "STATUS=1";
Ds = Rajprasad.ExcuteSqlwithsql(sql);
DataList1.DataSource = Ds;
DataList1.DataBind();
}
catch (Exception ex)
{
}
使用如下商店程序
use store procedure as below
create procedure usp_test
ddl1 int = 0 ,
ddl2 int = 0 ,
ddl3 int = 0 ,
ddl4 int = 0
as
begin
select * from <tablename>
where <field1> = case ddl1 when 0 then <field1> else ddl1 end and
<field2> = case ddl2 when 0 then <field2> else ddl2 end and
<field3> = case ddl3 when 0 then <field3> else ddl3 end and
<field4> = case ddl4 when 0 then <field4> else ddl4 end and
end
这篇关于在Asp.Net C#我有四个下拉列表,我想搜索他们选择的项目。条件如下框所示。救命!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!