使用复选框列表中的多个复选框来过滤数据列表中的结果
我希望为客户提供一个搜索,他们可以在其中选择多个类别 (复选框)并仅查看这些类别中的结果 网格视图控件。例如例子会 如果用户检查商品价格>则为100且价格< 100 那么他们只会获得与所选复选框相关的项目,并且所有其他选择标准不应填充到数据列表中。 我只是不知道如何根据选择生成动态多个查询,以及如何获取选定的复选框列表,以便我可以将其传递给 sql 查询。任何帮助或教程将不胜感激。此外,当取消选择该复选框时,该选择的项目应该从数据列表中消失。
已解决的问题:
static public DataTable GetSelectedFilter(ArrayList test)
{
string sqldef = "Select * from productDetail Where";
string sql = "";
int check = 0;
int number = test.Count;
string OR = "OR";
//ArrayList arrlist = new ArrayList();
if (test.Count > 0)
{
while (number > check)
{
sql += "((Price between " + test[number - 1] + "))" + OR;
number--;
}
string completeQuery = sqldef + sql;
string sqltest = completeQuery.Substring(0, completeQuery.Length - 2);
string finalQuery = sqltest + "order by Price";
SqlDataAdapter da = new SqlDataAdapter(finalQuery, ConnectionString);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
else
{
string sql1 = "Select * from productDetail";
SqlDataAdapter da = new SqlDataAdapter(sql1, ConnectionString);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
}
I am looking to provide a search for clients in which they can select multiple categores
(check boxes) and view only the results in those categories in a
gridView control. For instance example would
be if the user checks item price > 100 and price < 100 then they would only get items with respect to that checkbox selected and all the other selection criteria should not be populated to datalist.
I just dont know how to generate the dynamic multiple query depending on the selection and how will i get the selected checkbox list so that i can pass that to the sql query. Any help or tutorials will be appreciated. Also when the checkbox is deselected the items of that selection should dissapear from the datalist.
Issue Resolved:
static public DataTable GetSelectedFilter(ArrayList test)
{
string sqldef = "Select * from productDetail Where";
string sql = "";
int check = 0;
int number = test.Count;
string OR = "OR";
//ArrayList arrlist = new ArrayList();
if (test.Count > 0)
{
while (number > check)
{
sql += "((Price between " + test[number - 1] + "))" + OR;
number--;
}
string completeQuery = sqldef + sql;
string sqltest = completeQuery.Substring(0, completeQuery.Length - 2);
string finalQuery = sqltest + "order by Price";
SqlDataAdapter da = new SqlDataAdapter(finalQuery, ConnectionString);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
else
{
string sql1 = "Select * from productDetail";
SqlDataAdapter da = new SqlDataAdapter(sql1, ConnectionString);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原来是sql查询的问题,现在正常了
It was an issue with sql query , it works fine now