Sabilv
Sabilv

Reputation: 600

Search Datagridview column Value

I Have Datagridview, which the value come from sql datatable , and on of them is fill on Datagridview databound event :

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

now i want lookup the datagridview value which come from the code above. i already insert some code like this :

 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

it works but i do some tricky thing like, hide the row. is there any better solutions?

Upvotes: 1

Views: 270

Answers (1)

ivandinglasan
ivandinglasan

Reputation: 384

you can actually Search Datagridview column Value and display it by

filtering using ex. below just changed the corresponding values and variables

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")

Upvotes: 1

Related Questions