【问题标题】:Search Datagridview column Value搜索 Datagridview 列值
【发布时间】:2013-06-03 06:06:37
【问题描述】:

我有Datagridview,它的值来自sql datatable,其中一个是填充Datagridview数据绑定事件:

If e.Row.RowType = DataControlRowType.DataRow Then
    Dim dt As New DataTable
    Dim Ct As Integer
    Dim rspn As Integer
    Dim textrspn As String
    Dim RefNo As Label = CType(e.Row.FindControl("lblRefNo"), Label)
    If CPayment.Revstatus(RefNo.Text, Ct, rspn, textrspn) Then
        CType(e.Row.FindControl("lblRevResp"), Label).Text = textrspn.ToString
    End If
End If

现在我想查找来自上面代码的 datagridview 值。我已经插入了一些这样的代码:

 If DropDownList1.SelectedIndex = 1 Then
                    If Ct = 1 Then
                        CType(e.Row.FindControl("lblRevResp"), Label).Text = textrspn.ToString
                    Else
                        e.Row.Visible = False
                    End If

                ElseIf DropDownList1.SelectedIndex = 2 Then
                    If Ct = 0 Then
                        CType(e.Row.FindControl("lblRevResp"), Label).Text = textrspn.ToString
                    Else
                        e.Row.Visible = False
                    End If
                ElseIf DropDownList1.SelectedIndex = 0 Then
                    CType(e.Row.FindControl("lblRevResp"), Label).Text = textrspn.ToString
                End If

它有效,但我做了一些棘手的事情,比如隐藏行。有没有更好的解决方案?

【问题讨论】:

    标签: asp.net vb.net search gridview data-binding


    【解决方案1】:

    您实际上可以搜索 Datagridview 列的值并显示它

    使用 ex 过滤。下面只是改变了对应的值和变量

    Dim sql As String = "SELECT * FROM tblOfficeEquipmentProfile WHERE OE_ID  LIKE + '%'"
            sqlconn.Open()
            sCommand = New SqlCommand(sql, sqlconn)
            sAdapter = New SqlDataAdapter(sCommand)
            sBuilder = New SqlCommandBuilder(sAdapter)
            sDs = New DataSet
            sAdapter.Fill(sDs, "tblOfficeEquipmentProfile")
            sTable = sDs.Tables("tblOfficeEquipmentProfile")
            sqlconn.Close()
            DataGrid1.DataSource = sDs.Tables("tblOfficeEquipmentProfile")
    

    【讨论】:

    • 没问题,我忘了添加,即通过搜索通配符字符串,它的工作方式就像显示所有输入相同字母或数字的记录一样。你可以去掉 LIKE % 来显示一个更准确的
    猜你喜欢
    • 1970-01-01
    • 2012-10-21
    • 1970-01-01
    • 1970-01-01
    • 2010-11-09
    • 1970-01-01
    • 1970-01-01
    • 2012-01-09
    • 2011-12-01
    相关资源
    最近更新 更多