Solved

Hiding a datagrid if it's empty

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

828 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