2016-11-22 36 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