I would like to filter Gridview1 with, control checkbox, and code as "If GridView1 rows of column FirstName have value 'John' then show only this rows."

I have somehow with network help write this code. But code is not working as it should, and also I do not know how to add controls also for other rows with values such as 'James', 'Paul'...

For Each x As GridViewRow In Me.GridView1.Rows
If Not x.Cells(0).Value = "John" Then
x.Visible = False
End If

FirstName; SecondName
James ; White
John ; Brown
Paul ; Red
John ; Black
Paul ; Blue
James ; Green

So, need someone for help, to give a tip, or to show how would be easier.

Thank you in advance for help.

Here is my latest code, if someone would maybe need it:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        SqlDataSource1.SelectCommand = "SELECT * FROM MAIN WHERE FIRSTNAME like '%" & TextBox1.Text & "%' and secondname like '%" & TextBox2.Text & "%'"


    End Sub
Be a part of the DaniWeb community

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