【问题标题】:filtering out dataset to eliminate one value过滤数据集以消除一个值
【发布时间】:2016-11-22 19:26:22
【问题描述】:

我的数据集中只有四个值:

Value1
Value2
Value3
Value4

我想过滤我的数据集,使其只有 Value1、value2 和 Value3。我不想在我的数据集中使用 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。

任何帮助将不胜感激。

【问题讨论】:

    标签: asp.net vb.net


    【解决方案1】:

    您可以使用 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()
    

    【讨论】:

    • 什么是 order.AsEnumerable()。它给了我一个错误,说没有声明订单
    猜你喜欢
    • 2021-10-18
    • 2019-07-08
    • 2019-06-12
    • 1970-01-01
    • 2019-01-17
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多