I am not a C# developer, so can't provide you the exact code, but possible logic for achieving this will be -
say for example, you have a master list of all possible checkbox values
Now, rather then you are retrieving value from database everytime a value is checked, this should be triggered through a button (form submit) which will pass all of the checked values.
In the backend, you retrieve all these checked value and loop it for generating dynamic query string. Something like below -
ObjectA = {array of master checkbox values}
ObjectB = {array of master checkbox value columns for preparing query}
ObjectC = {array of all checked values submitted}
StringQuery = "select x,y,z from mytable where ";
for(int i = 0; i < ObjectA.size(); i++) {
for(int j = 0; j < ObjectC.size(); j++) {
if(ObjectA[i] == ObjectC[j]) {
StringQuery += " " + ObjectB[i] + " = " + ObjectC[j];
break;
}
}
if(i+1 > ObjectA.size()) {
StringQuery += " AND ";
}
}
Many thanks,
Niral Soni