I have DataTable which brings me following data from database.
NameAddressCountryID
I want to filter the data on my side by LINQ: I have a checkbox list which has countries with IDs 1, 2, 3, 4. I want to get only results of the countries that are checked. e.g. 1, 2, 4 as CountryID by LINQ. And I want to bind that to grid view.
I am using the following code:
foreach (ListItem cBox in chkGodownlst.Items)
{
if (cBox.Selected)
{
var a = dt.AsEnumerable()
.Where(r => r.Field<int>("CountryID") == Convert.ToInt32(cBox.Value));
}
}
Try something like this: