开发者

Using Multiple Checkboxes in a Checkboxlist to filter results in a datalist

开发者 https://www.devze.com 2023-02-23 06:31 出处:网络
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

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;
    }

}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号