Search code examples
c#linqsplistitemsplist

Constructing a linq query with dynamic ListItem columns that are type boolean


"selectedBA" is the variable that contains a value determined @ runtime. how can i incorporate this into a linq statement that will give me all the items in a SPList where the dynamic column selectedBA is True in the item. Probably something simple i am over thinking... the dynamic column is Type Boolean in the SPList

DataTable dt = siteTemplateList.GetItems().GetDataTable();
var query = from template in dt.AsEnumerable()
            where template[selectedBA].Equals(true)
            select template;

Solution

  • try

    DataTable dt = siteTemplateList.GetItems().GetDataTable();
    var query = from template in dt.Rows
                where template[selectedBA].Equals(true)
                select template;