-2

I'm trying to populate a repeater with results based on specific check boxes being checked.

Table:

SearchTable    
----    
TableId - int(pk)
Name - varchar
Description - varchar
Active - bool
IsCheck1 - bool
IsCheck2 - bool

Function:

protected void btnCSumit_Click(object sender, EventArgs e)
{
    var query = _db.SearchTable.Where(x => x.Active);
    if(ckbOne.Checked)
        query = query.Where(x => x.isCheck1);
    if(ckbTwo.Checked)
        query = query.Where(x => x.isCheck2);

    query = query.OrderBy(c => c.Name);
    repResults.DataSource = query;
    repResults.DataBind();
}

The code works when ckbOne OR ckbTwo is true, but if ckbOne AND ckbTwo is true I need it to do something like this

query = query.Where(x => x.isCheck1 || x.isCheck2);

Edit: hopefully made the question a bit more informative.

JamesD
  • 63
  • 1
  • 2
  • 8
  • possible duplicate of [Dynamic where clause (OR) in Linq to Entities](http://stackoverflow.com/questions/14621450/dynamic-where-clause-or-in-linq-to-entities) – Gert Arnold Sep 16 '14 at 20:08

1 Answers1

0

Try using below.

_db.table.Where(x => x.Active && ((check1 && x.isCheck1) || (check2 && x.isCheck2)))
Simon Whitehead
  • 63,300
  • 9
  • 114
  • 138
Max
  • 458
  • 3
  • 7