Select / Deselect all checkbox in gridview in VB.NET
By bryan tugade
We can select and deselect checkbox in gridview in onPostback event of checkbox in gridview header.
Protected Sub CheckBox2_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim gv As GridViewRow
Dim chkH As CheckBox = CType(GridView1.HeaderRow.FindControl("CheckBox2"), CheckBox)
If chkH.Checked = True Then
For Each gv In GridView1.Rows
Dim chk As CheckBox = CType(GridView1.Rows(gv.RowIndex).FindControl("CheckBox1"), CheckBox)
chk.Checked = True
Next
Else
For Each gv In GridView1.Rows
Dim chk As CheckBox = CType(GridView1.Rows(gv.RowIndex).FindControl("CheckBox1"), CheckBox)
chk.Checked = False
Next
End If
End Sub
Here is the sample image output.
Related FAQs
In C#, we can select and deselect checkbox in gridview in onPostback event of checkbox in gridview header.
We can find checkbox inside gridview by using Findcontrol.
Select / Deselect all checkbox in gridview in VB.NET (3289 Views)