Solved

Hiding a datagrid if it's empty

Posted on 2004-09-07
5
315 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

617 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