对象引用未设置为gridview中具有复选框的对象实例

时间:2014-03-20 15:45:18

标签: vb.net-2010

 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

0 个答案:

没有答案