嗨我进入一个homefinder项目,应该有一个高级搜索过滤器。它应该有用户可以从中选择租金数量,位置和性别类型的3个下拉列表,或者用户也可以不选择任何因为它具有默认值“ALL”,这导致显示存储在数据库中的所有房屋,但是如果用户从下拉列表中选择一个或两个值,其他默认值为“ALL”,或者所有三个值均具有值,则应该导致它们的结合。我试着用if语句使用多重下拉列表在c#中进行高级搜索
If (combobox1.text == "ALL" && combobox2.text == "ALL" && combobox3.text == "ALL")
{
// shows all the homes
}
else if (combobox1.text != "ALL" && combobox2.text == "ALL" && combobox3.text == "ALL")
{
// say combobox1 is rent amount, shows all the homes having that rent amount
}
else if (combobox1.text == "ALL" && combobox2.text != "ALL" && combobox3.text == "ALL")
{
// say combobox2 is gender type shows all the homes having that gender category
if (combox2.text == "Female")
// all homes w "female"
else
// all homes w male
}
else if (combobox1.text == "ALL" && combobox2.text == "ALL" && combobox3.text != "ALL")
{
// say combobox3 is location, shows all homes in that location
}
else if (combobox1.text != "ALL" && combobox2.text != "ALL" && combobox3.text != "ALL")
{
}
else if (combobox1.text != "ALL" && combobox2.text != "ALL" && combobox3.text == "ALL")
{
}
等等,这是我到目前为止想到的代码:l我怎样才能使它们相交。就像我选择500下的租金和位于第一街的位置,我怎么能找到位于第一街的500个房租?
顺便说一下,我已经知道如何展示家园。我担心的是如何在下拉列表中找到这些项目的交叉点。
你的任何帮助都是可以理解的。谢谢
你运行你的搜索针对Sql Server ..?如果是的话,编写一个简单的方法,在你点击搜索按钮后,它进入该事件,然后你可以将3盒的值传递给存储过程,创建一个基于'IS NULL'检查的简单选择,这实际上更容易比你想象的要多。在存储过程或代码中,你可以使用case语句或条件来处理'ALL'关键字。还要查看如何使用'LIKE'关键字并理解SQL WILDCARDS%''以及如何使用它们。 – MethodMan
好的,我会继续努力。谢谢。 – user6079070