Click to See Complete Forum and Search --> : GridView RowCreated Event Causing Problems!


lmf232s
04-20-2007, 04:27 PM
When i click on a column to sort within the gridview, it seems to be executing the RowCreated Sub before it actually executs the Sorting Sub.

This is causing problems as i have code in the RowCreated Sub that gets the DataItem's for a couple of rows and does some stuff (change background colors, etc).

Im just curious if there is some kind of select case or if statement that i can put into place to avoid the error im getting.

Protected Sub gvInventory_Sorting(........)
'Sorting Code Here
End Sub

Protected Sub gvInventory_RowCreated(............)
Select Case e.Row.RowType
Case DataControlRowType.DataRow
'ERROR IS HAPPENING HERE
Dim Field1 as String = e.Row.DataItem("Field1")
Dim Field2 as String = e.Row.DataItem("Field2")

End Select
End Sub


The error is:
System.NullReferenceException: Object variable or With block variable not set.

And i get this on the "Dim Field1 as String..............." line

Any Ideas