I've never tried doing this, but I think this will suit your needs:
Protected Sub TestGrid_RowDataBound(ByVal sender As Object, _
ByVal e As GridViewRowEventArgs)
Dim DVR As DataRowView = CType(e.Row.DataItem, DataRowView)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim Visible As Boolean = True
For i As Integer = 0 To e.Row.Cells.Count - 1
If DVR(i) Is Nothing Then
Visible = False
Exit For
End If
Next
e.Row.Visible = Visible
End If
End Sub
In the grid's
RowDataBound
event, first determine if you are binding a data row; we do not need to run this code on header rows, footer rows, etc.
Next, get a reference to the
DataItem
, for the row, casting it to
DataRowView
. This object has a default property, and you can reference the columns either by index or by column name.
Perform your checks: you can test every column using an integer loop, or just selected columns. The property returns an
Object
, so you may want to cast it to a specific data type to look for particular values (maybe you want to suppress the row if an integer column is less than zero, for example). If you use this with a data source from SQL, you would test against
DBNull.Value
to look for a SQL null.
If the row meets the specifications for "suppress this row", then simply set the row to be not visible. When the control gets rendered, any invisible rows will be omitted from the output.
Update I changed the sample code to be more in line with what you are asking for.