我有几个下拉列表来过滤来自gridview的数据,但工作正常,但我想添加Select Any,它显示没有过滤器的数据。
这是我在SQL数据源中的SelectCommand
SelectCommand="SELECT * FROM [Courses]
WHERE (([Language] = @Language) AND ([Level] = @Level)
AND ([endDate] = @endDate) AND ([startDate] = @startDate))"
答案 0 :(得分:0)
我遇到过类似的情况,我解决了它在运行时构建SelectCommand
的问题。首先在你的两个DropDownLists中添加一个选项“Any”,你需要在后面检查代码。
然后像这样检查后面的代码:
String query = "SELECT * FROM YourTable";
String extndQuery = "";
bool and = false;
if (dropdownlist1.SelectedValue != "Any")
{
extndQuery += " Column1=@variable1";
and = true;
}
if (dropdownlist2.SelectedValue != "Any")
{
if (and)
{
extndQuery += " AND";
}
extndQuery += " Column2=@variable2";
and = true;
}
if (and)
{
query += " WHERE" + extndQuery;
}
SelectCommand=query;