A
Adam Knight
Hi all,
The following code works fine.
If i remove the try statement, i recieve a generic is null exception when
trying to retrieve a datagrids data item.
With the try those exceptions are obviously caught, but it is clear the data
item is accessible otherwise as i am able to use its value.
I am just wondering (without the try statement) what the function could be
encountering to set of the null exception error.
Any thoughts?
Adam
Sub dgAnswerOptions_ItemDataBound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)
'determine if current item is not a header or footer
If(e.Item.ItemType <> ListItemType.Header Or e.Item.ItemType <>
ListItemType.Footer) Then
'add index to answer options
e.Item.Cells(0).Controls.Add(New
LiteralControl(e.Item.ItemIndex + 1 & "."))
'determin if logged in user belongs to the director or admin
groups
If(Security.IsDirector() Or Security.IsAdmin()) Then
Try
'determine if current option is a correct option
If(e.Item.DataItem.Item(2) = 1) Then //error occurs
here without try
'change cell formatting to reflect a correct
answer
e.Item.Cells(1).CssClass = "correct"
e.Item.Cells(1).Text = e.Item.Cells(1).Text & "
(Correct)"
End If
Catch
e.Item.Cells(1).Controls.Add(New LiteralControl("
Type: " & e.Item.ItemType))
End Try
End If
End If
End Sub
The following code works fine.
If i remove the try statement, i recieve a generic is null exception when
trying to retrieve a datagrids data item.
With the try those exceptions are obviously caught, but it is clear the data
item is accessible otherwise as i am able to use its value.
I am just wondering (without the try statement) what the function could be
encountering to set of the null exception error.
Any thoughts?
Adam
Sub dgAnswerOptions_ItemDataBound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)
'determine if current item is not a header or footer
If(e.Item.ItemType <> ListItemType.Header Or e.Item.ItemType <>
ListItemType.Footer) Then
'add index to answer options
e.Item.Cells(0).Controls.Add(New
LiteralControl(e.Item.ItemIndex + 1 & "."))
'determin if logged in user belongs to the director or admin
groups
If(Security.IsDirector() Or Security.IsAdmin()) Then
Try
'determine if current option is a correct option
If(e.Item.DataItem.Item(2) = 1) Then //error occurs
here without try
'change cell formatting to reflect a correct
answer
e.Item.Cells(1).CssClass = "correct"
e.Item.Cells(1).Text = e.Item.Cells(1).Text & "
(Correct)"
End If
Catch
e.Item.Cells(1).Controls.Add(New LiteralControl("
Type: " & e.Item.ItemType))
End Try
End If
End If
End Sub