I'm trying to get values from numerous dropdown lists and build a where statement depending on the options selected. If they are not slected then they should be excluded from the select statement.
This is how I would have done it but I gather that it can not be done in this way with linq.
IEnumerable<IGrouping<string, Forest>> treeQuery =
from trees in Forest
if (ddlType1.SelectedValue!=null)
{
string strWhere += trees.Type1 == ddlType1.SelectedValue
}
else if (ddlType2.SelectedValue!=null)
{
string strWhere += trees.Type2 == ddlType2.SelectedValue
}
where strWhere
orderby trees.Nuts
group trees by trees.TrunkColour;
Any help would be greatly appreciated.
This is the code before I added the example in...
IEnumerable<IGrouping<string, Forest>> treeQuery =
from trees in Forest
where trees.Type1 == "oak"
orderby trees.Nuts
group trees by trees.TrunkColour;
=when I think you meant==