Sir,
I have a gridview and in that i'm using a header checkbox OnCheckedChanged="cbox_CheckedChanged" event in that checkbox.
This checked changed event fires twice and i get error when second time the event is firing object reference not set to instance of an object when i count the gridview rows to check or uncheck
this is code behnind
Protected Sub cbox_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ctrl As CheckBox = DirectCast(sender, CheckBox)
Dim grd As GridView = Nothing
Dim tempchar As String = ctrl.ID(ctrl.ID.Length - 1).ToString()
If tempchar = "1" Then
grd = MASTERGRD
ElseIf tempchar = "2" Then
grd = TRANSGRD
ElseIf tempchar = "3" Then
grd = REPORTGRD
End If
Dim rw As Integer = 0
Dim col As String = String.Empty
If ctrl.ID.ToUpper().Contains("ADD") Then
col = "cb_add"
ElseIf ctrl.ID.ToUpper().Contains("EDIT") Then
col = "cb_edit"
ElseIf ctrl.ID.ToUpper().Contains("DEL") Then
col = "cb_del"
ElseIf ctrl.ID.ToUpper().Contains("COPY") Then
col = "cb_copy"
ElseIf ctrl.ID.ToUpper().Contains("VIEW") Then
col = "cb_view"
ElseIf ctrl.ID.ToUpper().Contains("APPROVE") Then
col = "cb_app"
End If
If col IsNot Nothing Then
For rw = 0 To grd.Rows.Count - 1
If ctrl.Checked = True Then
DirectCast(grd.Rows(rw).FindControl(col), CheckBox).Checked = True
Else
DirectCast(grd.Rows(rw).FindControl(col), CheckBox).Checked = False
End If
Next
End If
End Sub