I'm trying to hide columns of the gridview that are null or empty and when I debug, at the first for loop it throws the object reference not set to instance of an object. I have tried for quite some time but I can't figure it out. Here is my code.
Protected Sub GridView1_RowDataBound(ByVal sender As Object,
ByVal e As GridViewRowEventArgs)
Dim Grid As GridView = FormView1.FindControl("GridView1")
Dim hasData As Boolean = False
Dim row As Integer
For col = 0 To Grid.HeaderRow.Cells.Count Step 1
For row = 0 To Grid.Rows.Count Step 1
If Not (String.IsNullOrEmpty(Grid.Rows(row).Cells(col).Text)) Then
hasData = True
End If
Next
Grid.Columns(col).Visible = hasData
Next
End Sub