Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I reference when my Gridview has no data?

Status
Not open for further replies.

snoopy80

Technical User
Jun 27, 2001
106
Good morning all,
When my Gridview is empty (no data meeting a criteria), how can I reference the condition in vb?
I tried this but obviously did not work

"if Gridview.Text = Null then"

Thanks for help
 
Or you could check the underlying data source first..not sure if that's an option or not.

Regards,

J
 
Thank tperri for your help.

I tried it, it worked but then I realize that Rows.Count does not change right away. What I mean is:
I have a drop down list, when I select a name for example, the gridview will display information on the name selected, and when there is no info then it will display a message as "No results Found". I first select a name that has no data and message no results displayed works great (I though) then I select a name that has info, it did display the info but it also display the message no result found, then when I select another name then info would display and message would hide. The same thing happens if I select a name with info display then I select a name that has no data, no gridview showed and no message, then select another no data name and message would disply back.

Here is some of the code
Protected Sub NameDropDownList_SelectedIndexChanged(...)
NameGridView.Visible = True
If NameGridView.Rows.Count = 0 Then
MessageLabel.Visible = True
MessageLabel.Text="No Results found"
End If....

I tried several things and none of them solve my problem. What did I do wrong? Thanks for help
 
You have to check in whatever sub/function you get the data in. If there is no data display the message and hide the grid. Doing it in the ddl's selectedindexchanged will not work, since at that point you did not retrieve the data and have no idea if there is any data for that person or not.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top