Friday, February 12, 2010

ASP.NET- Repeater control. Check for number of rows!!?

Hi Gurus





In my Asp.net page I use a Repeater contol to display data read from an access database using SQL qurey. I do this using an Oledb connection using the following lines of code.





MyRepeater.DataSource = Cmd.ExecuteReader(System.Data.CommandBeh鈥?br>




MyRepeater.DataBind()





The problem is; if the query returns no matching records, I want to display an info messsage to the user. How can I do it ?Or How can I check wheather myRepeater is empty??





Regards.ASP.NET- Repeater control. Check for number of rows!!?
The System.Web.UI.WebControls.Repeater control contains a collection of RepeaterItems. You can access it using the Items property.


I believe it won't show things in the footer template if there are no items, so you can put stuff that should show there (I know for a fact that the header template does this).





int numberOfItems = repeater1.Items.Count;ASP.NET- Repeater control. Check for number of rows!!?
Try this:





if (Repeater1.Items.Count == 0)


Label1.Text = ';Empty';;





You can also check out the website www.asp.net, it's a great resource for .NET web developers
  • Scooter
  • No comments:

    Post a Comment