我有一个搜索页面,其中包含一系列3个下拉菜单,用户可以使用这些下拉菜单来限制搜索结果。每个下拉列表的初始值为ALL。如果任何值具有除ALL之外的值,则需要将其包含在WHERE语句中。
这是我陷入困境的地方。我的Linq Select是......
Dim myComponents = From searchComponents In dc.Components _
Where searchComponents.Type = ddl_Type.SelectedValue _
AndAlso searchComponents.Size = ddl_Size.SelectedValue _
AndAlso searchComponents.WR = ddl_WR.SelectedValue _
Select searchCompnents)
目前我的搜索将包含所有ddl selectedValues。我需要删除任何值为ALL的东西。我希望我已经正确解释了。示例如果ddl_Size.SelectedValue = "ALL"
那么我的陈述将是......
Dim myComponents = From searchComponents In dc.Components _
Where searchComponents.Type = ddl_Type.SelectedValue _
AndAlso searchComponents.WR = ddl_WR.SelectedValue _
Select searchCompnents)
如何在代码中实现此目的。感谢
答案 0 :(得分:4)
Dim myComponents = From searchComponents In dc.Components _
Where (ddl_Type.SelectedValue = "ALL" OrElse searchComponents.Type = ddl_Type.SelectedValue) _
AndAlso (ddl_Size.SelectedValue = "ALL" OrElse searchComponents.Size = ddl_Size.SelectedValue) _
AndAlso (ddl_WR.SelectedValue = "ALL" OrElse searchComponents.WR = ddl_WR.SelectedValue) _
Select searchCompnents)