Link to home
Start Free TrialLog in
Avatar of fernandezf
fernandezf

asked on

Hiding a datagrid if it's empty

I use a datareader to populate a datagrid.

Sub BindGrid()
            ' and bind to the datalist control
            Dim documents As New ASPNetPortal.UALDB()

            myDataGrid.DataSource = documents.UALGetDocuments(pilotinfo)
            myDataGrid.DataBind()


        End Sub

I like to hide the hide the datagrid if it doesn't return any information, but I don't know how to do that.  
Avatar of AerosSaga
AerosSaga

create a dataset, check for empty dataset, if not empty set datagrid to visible:

If ds.Tables.Count > 0 And ds.Tables(0).Rows.Count > 0 Then
     lblNoResults.Visible = False
Else
     lblNoResults.Visible = True
End If

Regards,

Aeros

I beleive you autogenerating the columns, if so

Try this

mydatagrid.columns(0).visible = false


he wants to hide the entire datagrid not a column
Avatar of fernandezf

ASKER

How about if I still want to bind the datagrid with a datareader?
ASKER CERTIFIED SOLUTION
Avatar of raterus
raterus
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial