datagrid with no records - showing a line

T

Tony Farrell

Hi everyone,

Using asp.net and a datagrid -

When there are no records returned from
the query - is there a way to add/insert
a line into the grid stating there is/are
no records to display???

thanks
tony
 
S

Scott Mitchell [MVP]

I've found the easiest way is after binding, check to see if there are no
records returned. If not, hide the DataGrid and show a Label that says,
"No records," or whatnot. If there are records, then do the opposite.

That is, you might have something like:

myDataGrid.DataSource = ...
myDataGrid.DataBind()

If myDataGrid.Items.Count = 0 then
'There are no records
myDataGrid.Visible = False
someLabelWithAMessage.Visible = True
Else
myDataGrid.Visible = True
someLabelWithAMessage.Visible = False
End If


Happy Programming!

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top