【发布时间】:2018-06-04 04:29:41
【问题描述】:
我有一个包含员工数据的数据表,此数据绑定到网格视图。我在网格视图中有国家、排名、部分的标题下拉列表。 whenever a selected drop down index changes, i use LINQ to get data as per Say country drop down and save it in Viewstate for further Filtering operations.这很好用。
我将过滤器值保存在字典中,例如 DictionaryFilters,如果没有设置过滤器,则键的值设置为 ALL。
例如,我选择国家,然后选择部分。过滤后的数据很好。但如果我将国家设置为全部,部分过滤器仍然存在。由于我的网格中有 4-5 个过滤下拉列表,如何仅使用一个 LINQ 查询和使用字典值而不是多个条件查询来查询数据表中的数据。是否有任何 % 用于选择列,以便我将字典值中的 ALL 更改为这个特定的运算符?
filter["Country"]="UK"; filter["Section"]="HR"; filter["rank"]="All";
var query = from a in datatable
where a.Field<string>("Country")filter["Country"] &&
a.Field<string>("Section")==filter["Section"] &&
a.Field<string>("Rank")==filter["rank"]
select a;
【问题讨论】: