I want to filter the datagridview on Search button click,i am using 3-tier architecture,the grid should be updated with the search result

you need to use dataview and filter the dataview with dataview.rowfilter method and bind the result back to the grid.

i tried but its not working

Show your code here..

 For i = 0 To (GrdUnitsOfMeasure.RowCount - 2)
                For j = 0 To (GrdUnitsOfMeasure.ColumnCount - 1)
                    If (GrdUnitsOfMeasure.Rows(i).Cells(j).Value.ToString.ToLower.StartsWith(TxtSearch.Text)) Then
                        GrdUnitsOfMeasure.Rows(i).Cells(j).Style.BackColor = Color.Red
                     else
                     MessageBox.Show("No Records Found")
                     EndIf
                     Next
                     Next

I want to highlight only the content

Where is the code for Dataview and rowfilter?

the above is
my code i didnt used the dataview or row filter

 Try
            Dim cn As SqlConnection
            Dim strCnn As String = "Your data base connection string"
            cn = New SqlConnection(strCnn)
            cn.Open()
            Dim comm As New SqlCommand("Your sp or Command text to get the data from DB", cn)
            '' If ur using Sp then Commandtype= CommandType.StoredProcedure if it is Text then comm.CommandType=CommandType.Text
            comm.CommandType = CommandType.StoredProcedure
            Dim da As New SqlDataAdapter(comm)
            Dim ds As New DataSet
            da.Fill(ds)

            Dim dv As New DataView
            dv = dsNew.Tables(0).DefaultView
            dv.RowFilter = "Name = '" & "John" & "'"

            ''Close your connections and commands.
        Catch ex As Exception
            ''Handle error if any
        End Try

try something like this code.
Note:Code above is not tested. You need to change the filter criteria to your need.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.