搜索Datagridview列值

时间:2013-06-03 06:06:37

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

我有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

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

1 个答案:

答案 0 :(得分: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")