如何在过滤的gridview中显示完整数据

时间:2014-08-20 13:59:49

标签: c# asp.net gridview

我有几个下拉列表来过滤来自gridview的数据,但工作正常,但我想添加Select Any,它显示没有过滤器的数据。

http://i.imgur.com/zwIw23t.jpg

这是我在SQL数据源中的SelectCommand

SelectCommand="SELECT * FROM [Courses]
WHERE (([Language] = @Language) AND ([Level] = @Level)       
AND ([endDate] = @endDate) AND ([startDate] = @startDate))"

1 个答案:

答案 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;