首页 > 解决方案 > 如何在 devexpress vb.net 上按 ID 进行行过滤?

问题描述

我需要从我的数据库中过滤 LOTID 值,但我的 rowfilter 在 devexpress gridview 上不起作用。

数据库列名称为 LOTID ,LOTID 的行值示例为 L-S3FH2

我的代码如下:

Protected Sub ClipData()

      ......... 

       connx.Close()

        'Dim RowLotID As String = DetailGridx.GetRowValues("LotID").ToString

        Dim dv2 As DataView = New DataView(dt1)

        'dv2.RowFilter = "LOTID = 'L-" + RowLotID + "'"

        DetailGridx.DataSource = dv2
        DetailGridx.DataBind()

    End Sub

请指导我,在此先感谢。

标签: vb.netdevexpress

解决方案


文档中,ASPxGridView.GetRowValues()重载应该是这样的:

Public Function GetRowValues( 
   ByVal visibleIndex As Integer,  
   ByVal fieldNames As String[] 
) As Object

第一个参数是Integer,因此当前的重载使用是错误的,因为您将字符串传递给visibleIndex参数。

您应该使用可见索引EventArgs作为第一个参数(VisibleIndex属性值为 an Integer)并在第二个参数中提及列名,如下所示:

Dim RowLotID As String = DetailGridx.GetRowValues(e.VisibleIndex, "LotID").ToString()

或使用IDKeyFieldName中的属性ASPxGridView

Dim RowLotID As String = DetailGridx.GetRowValues(e.VisibleIndex, DetailGridx.KeyFieldName).ToString()

然后您可以对RowFilter过滤字符串使用字符串格式:

Dim dv2 As DataView = New DataView(dt1)
dv2.RowFilter = String.Format("LOTID='{0}'", "L-" & RowLotID)

推荐阅读