most of us are using Repeaters to display Data also we faced the situation of retrieving no result to display so the Repeater will be Empty or we will need to handle this case from code behind to check the number of items and if zero we show a label with No Result found or no records to display message.
we can do this with a simpler way and with no need to write anything in code behind ,let's see how
<asp:Repeater ID="RptrContacts" runat="server">
<ItemTemplate>
<!-- Add your Item Template Here -->
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblEmpty"
Text="no result" runat="server"
Visible='<%#bool.Parse((RptrContacts.Items.Count==0).ToString())%>'>
</asp:Label>
</FooterTemplate>
</asp:Repeater>
here we will display a label with "no result" message in the footer we just need to add a label and set it's text property with the message we want.
then we set the Visible property of the label with the value coming out from the following expression
<%#bool.Parse((RptrContacts.Items.Count==0).ToString())%>
it checks if the number of Items equals zero or not , if it equals zero it returns True so the label will be visible and if not it will return False so the label will be invisible.

16 comments:
Wanted to say how helpful this was. Thanks!
Very very helpful!!! Thank you!
Hi,
Here is my approach http://blog.sb2.fr/post/2008/12/12/How-To-Handle-Empty-Data-With-ASPNET-Repeater.aspx
Thanks.
Yeah! This is a much simpler solution. Thank you!
Excellent, thank youi.
excellent trick buddy.. quite impressed..
Just a little hint: you don't need to convert the expression to a string then call bool.Parse. evaluation of the expression will return a bool anyway. for example, writeing an if statement like this "if(rpt.Items.Count == 0)" is the same as writing if(true) or if(false), given the outcome of the expression. so there is no need to convert the expression to a string representation and then back again.
Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!
Compiler Error Message: CS0103: The name 'RptrContacts' does not exist in the current context
just what i'm looking for, simple and elegant :)
Thanks alot. Very helpful article.
This is a nice article..
Its very easy to understand ..
And this article is using to learn something about it..
web designing/development
Thanks a lot..!
Great, thanks - got it to work also with a simpler line: [asp:Label Text="No data" Visible='[%# Repeater1.Items.Count==0 %]' runat="server" /]
(Replace square brackets with angled ones - can't use those in this comment box.)
Thanks!
Great Buddy.....
thankx man, this is amazing an easy one ;-)... great job :-)
H. Ahmed
Great solution ;) It's very helpful
Post a Comment