2016-11-22 42 views
1

我只有在我的数据集四个值:过滤掉数据集来消除一个值

Value1 
Value2 
Value3 
Value4 

我要筛选我的数据集,使其不仅具有值1,值2和值3。我不想在我的数据集中使用value4,然后我想使用此数据集绑定我的下拉列表。以下是我迄今为止:

 Dim ds As New DataSet 
     ds = SelectionProdCriteria.GetCostType() 
     ds.Tables(0).DefaultView.RowFilter = "CostType=Value4" 
     ddlCostType.DataSource = ds 
     ddlCostType.DataValueField = "CostType" 
     ddlCostType.DataTextField = "CostType" 
     ddlCostType.DataBind() 

我在ds.Tables(0).DefaultView.RowFilter = "CostType=Value4"得到一个错误说支持运营商后失踪操作数。

我只想在我的下拉列表中看到value1,value2和Value3并过滤掉value4。

任何帮助将不胜感激。

回答

0

您可以使用Linq。只需获取所有没有Value4的元素,如下所示:

Dim query = From ct In ds.Tables(0).AsEnumerable() _ 
    Where ct.Field(Of String)("CostType") != Value4 
    Select ct 
Dim view As DataView = query.AsDataView() 
ddlCostType.DataSource = view 
ddlCostType.DataValueField = "CostType" 
ddlCostType.DataTextField = "CostType" 
ddlCostType.DataBind() 
+0

什么是order.AsEnumerable()。它给我一个错误,说Orders没有声明 – Anjali5