Private Sub GetData()
Dim arr As ArrayList
If ViewState("SelectedRecords") IsNot Nothing Then
arr = DirectCast(ViewState("SelectedRecords"), ArrayList)
Else
arr = New ArrayList()
End If
Dim chkAll As CheckBox = DirectCast(viewEmployeeGridView.HeaderRow.Cells(0).FindControl("chkAll"), CheckBox)
For i As Integer = 0 To viewEmployeeGridView.Rows.Count - 1
If chkAll.Checked Then
If Not arr.Contains(viewEmployeeGridView.DataKeys(i).Value) Then
arr.Add(viewEmployeeGridView.DataKeys(i).Value)
End If
Else
Dim chk As CheckBox = DirectCast(viewEmployeeGridView.Rows(i).Cells(0).FindControl("chk"), CheckBox)
If chk.Checked Then
If Not arr.Contains(viewEmployeeGridView.DataKeys(i).Value) Then
arr.Add(viewEmployeeGridView.DataKeys(i).Value)
End If
Else
If arr.Contains(viewEmployeeGridView.DataKeys(i).Value) Then
arr.Remove(viewEmployeeGridView.DataKeys(i).Value)
End If
End If
End If
Next
ViewState("SelectedRecords") = arr
End Sub