使用复选框列表中的多个复选框来过滤数据列表中的结果

发布于 2024-10-31 12:41:27 字数 1296 浏览 1 评论 0原文

我希望为客户提供一个搜索,他们可以在其中选择多个类别 (复选框)并仅查看这些类别中的结果 网格视图控件。例如例子会 如果用户检查商品价格>则为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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往昔成烟 2024-11-07 12:41:28

原来是sql查询的问题,现在正常了

It was an issue with sql query , it works fine now

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文