Default text for blank or empty datalist

  • Thread starter Thread starter j_ruez
  • Start date Start date
J

j_ruez

I have looked everywhere and honestly can't believe I am the only one
trying to figure this out. Maybe I am searching under the wrong
keywords.

I have a datalist. It is bound to an array, but could be bound to
anything - dataset, whatever. If, when bound, there are no values,
all that shows on the datalist is the header and the footer, with no
space in between. I want to display a default message - something
like "There are no values"

Any ideas?
 
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!
 
Back
Top