Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Hiding a datagrid if it's empty

Posted on 2004-09-07
5
Medium Priority
?
316 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

722 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