我正在使用 Linq to Entities 并添加了using System.Linq.Dynamic;
我的目标的 using stmt 是将whereClause
变量传递到 emailList 查询(见屏幕截图)。
有什么想法吗?
++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++
使用@Michael建议后,我得到了它与以下内容一起使用:
HTML(注意我将字段值放在“值”属性中。):
<asp:CheckBoxList ID="_checkboxGroups" runat="Server">
<asp:ListItem Text="Sid Dickens Lovers" Value="SidDickens_TF" Selected="False" />
<asp:ListItem Text="Rosamond Lover" Value="Rosamond_TF" Selected="false" />
<asp:ListItem Text="Wine and Cheese Lovers" Value="WineAndCheese_TF" Selected="false" />
<asp:ListItem Text="Good Clients" Value="IntDesign_TF" Selected="false" />
<asp:ListItem Text="Vendors" Value="Vendor_TF" Selected="false" />
</asp:CheckBoxList>
后面的代码:
// determine # of items in asp:CheckBoxList
var groupCount = _checkboxGroups.Items.Count;
var conditions = new List<string>();
for (int i = 0; i < groupCount; i++)
{
if (_checkboxGroups.Items[i].Selected)
{
conditions.Add(_checkboxGroups.Items[i].Value.ToString() + " == true");
}
}
string whereClause = string.Join(" OR ", conditions.ToArray());
ElanEntities3 db = new ElanEntities3();
var emailList = (from c in db.vEmailListViewforSendings
orderby c.Email
select c).AsQueryable();
emailList = emailList.Where(whereClause);
_listViewClients.DataSource = emailList;