Solved

Hiding a datagrid if it's empty

Posted on 2004-09-07
5
310 Views
Last Modified: 2008-02-26
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.  
0
Comment
Question by:fernandezf
5 Comments
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
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
0
 
LVL 1

Expert Comment

by:rk_1972
Comment Utility

I beleive you autogenerating the columns, if so

Try this

mydatagrid.columns(0).visible = false


0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
he wants to hide the entire datagrid not a column
0
 

Author Comment

by:fernandezf
Comment Utility
How about if I still want to bind the datagrid with a datareader?
0
 
LVL 33

Accepted Solution

by:
raterus earned 125 total points
Comment Utility
you could also check the Items collection for an empty datagrid, if you code doesn't already use a dataset (probably should be though)

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

if myDataGrid.Items.count = 0 then
  myDataGrid.visible = false
end if
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now