Solved

Hiding a datagrid if it's empty

Posted on 2004-09-07
5
312 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
ID: 12000236
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
ID: 12000245

I beleive you autogenerating the columns, if so

Try this

mydatagrid.columns(0).visible = false


0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12000252
he wants to hide the entire datagrid not a column
0
 

Author Comment

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

Accepted Solution

by:
raterus earned 125 total points
ID: 12000332
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
daypilot scheduler 3 27
Output Caching in IIS 2 29
ASP.net 2015 Syncing Azure web app projects on two machines 2 21
Winform Module - What is the ASP.Net equiv 2 21
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

772 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