1

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

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

4

1 回答 1

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")
于 2013-06-03T07:33:33.957 回答