Feb 23 2008

Empty Datalist: show message?

Category: ASP.NETpaomic @ 11:36 am

If you have a ASP.NET datalist and you need to show a message when there are no items in the list, you can use a code like the following:

myDataGrid.DataSource = …;
myDataGrid.DataBind();

if(myDataGrid.Items.Count == 0)
{
myDataGrid.Visible = false;
someLabelWithAMessage.Visible = true;
}
else
{
myDataGrid.Visible = true;
someLabelWithAMessage.Visible = false;
}

This is for C#, for VB it wuold be 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 coding!

Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • description
  • ThisNext
  • MisterWong
  • Wists
  • blinkbits
  • BlinkList
  • blogmarks
  • BlogMemes
  • blogtercimlap
  • Blue Dot
  • description
  • Bumpzee
  • co.mments
  • De.lirio.us
  • Fark
  • feedmelinks
  • Fleck
  • Furl
  • Gwar
  • kick.ie
  • Linkter
  • Ma.gnolia
  • MyShare
  • Netscape
  • NewsVine
  • Scoopeo
  • Simpy
  • Slashdot
  • Smarking
  • Spurl
  • StumbleUpon
  • Taggly
  • Technorati
  • Webride
  • YahooMyWeb
Post Tagged:

Leave a Reply