Avatar of andrewmilner
andrewmilner

asked on 

How to hide an ASP.net Lable if GridView or ObjectDataSource is empty

Okay so I have an ObjectDataSource (ObjectDS) and a GridView (GridView1) in my ASP.net vb project.

There are various details views and things below the grid view whos visible states are changed to true when the GridView selected index is changed.

I also have an asp.net label that contains text of 'Select an item to view Details'.

I need a way to hide this if the GridView or ObjectDS is empty.  I know you can have an empty template of the Gridview to state No data found but I also need to hide this label.

Hope you can help.
Microsoft Development

Avatar of undefined
Last Comment
havj123
SOLUTION
Avatar of ororiole
ororiole
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of andrewmilner
andrewmilner

ASKER

Wow, that looks simple.  One quick question though if I may,  the Gridview and datasource has been added using the GUI so there is no reference to the DataBind in the code behind.

How would I therefore enter this, where abouts in the code behind?  Below is the current code behind.
Imports System.Data
 
Partial Class incoming_returns
    Inherits System.Web.UI.Page
 
    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
        ReturnDetailsView.Visible = True
        CustomerDetailsView.Visible = True
        FaultDetailsView.Visible = True
        ShowDetailsMessage.Visible = False
    End Sub
 
 
End Class

Open in new window

SOLUTION
Avatar of ororiole
ororiole
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
Avatar of ororiole
ororiole
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of andrewmilner
andrewmilner

ASKER

Hi.  Sorry for the late reply.

I've tried the code but it doesn't work no.

This is what I have in there at the moment.  Maybe it's because the GridView1 isn't event loaded becasue there is no data.  Would we be better referencing the ObjectDataSource and checking that for data?
    Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
        If GridView1.Rows.Count = 0 Then
            ShowDetailsMessage.Visible = False
        End If
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of havj123
havj123
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Microsoft Development
Microsoft Development

Most development for the Microsoft platform is done utilizing the technologies supported by the.NET framework. Other development is done using Visual Basic for Applications (VBA) for programs like Access, Excel, Word and Outlook, with PowerShell for scripting, or with SQL for large databases.

48K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo