Yasserzaid’s Weblog

February 19, 2009

Handling Empty Data in DataList control

Filed under: ASP.Net — Tags: — yasserzaid @ 8:09 am

Hi

try this Example to Handle Empty Data in Datalist control

<asp:DataList ID="dlContacts" runat="server">
<ItemTemplate>

<!-- Add your Item Template Here -->

</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblEmpty" Text="no result" runat="server"
     Visible='<%#bool.Parse((dlContacts.Items.Count==0).ToString())%>'>
</asp:Label>
</FooterTemplate>
</asp:DataList>

Hope this helps

Good Luck

24 Comments »

  1. Thank You… really helpful..

    Comment by Nitish — July 24, 2009 @ 6:38 pm

  2. Thank you very much… It was very helpful…

    Comment by Mushtaq — July 16, 2010 @ 11:46 am

  3. @Nitish , @Mushtaq : Thank you for your comment hope my post helps you … Good Luck

    Comment by yasserzaid — July 16, 2010 @ 5:26 pm

  4. There is no built-in empty template for DataList control, but you can use a label to show the message by using your dataSource selected event:

    OnSelected=”SqlDataSource1_Selected”

    Protected Sub SqlDataSource1_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource1.Selected

    If e.AffectedRows = 0 Then
    myLabel.Text = “No record found!”
    Else
    myLabel.Text = “”
    End If
    End Sub

    Comment by e — August 16, 2010 @ 7:38 am

  5. Thanks for your information GoodLuck

    Comment by yasserzaid — August 21, 2010 @ 10:00 pm

  6. Visible=”
    can be reduced to
    Visible=”

    Comment by erratic — January 18, 2011 @ 2:28 pm

  7. ahem, next try:

    Visible= '<%# bool.Parse((dlContacts.Items.Count==0).ToString()) %>'
    can be reduced to
    Visible= ' < %# dlContacts.Items.Count==0 % > '

    Comment by erratic — January 18, 2011 @ 2:33 pm

  8. @erratic :- thank you for your information as you know you can find many ways to do something hope my post helps you… GoodLuck

    Comment by yasserzaid — January 19, 2011 @ 6:08 am

  9. Thank you … helps a lot

    Comment by mohamed — March 1, 2011 @ 8:10 am

  10. thank u

    Comment by mohamed — March 1, 2011 @ 8:11 am

  11. @Mohamed :- You are welcome hope my post helps you :)

    Comment by yasserzaid — March 1, 2011 @ 7:46 pm

  12. Thanks Bro!

    Varun Maggo

    Comment by Varun Maggo — September 2, 2011 @ 11:10 am

  13. @Varun Maggo :- you are welcome Good Luck

    Comment by yasserzaid — September 2, 2011 @ 8:41 pm

  14. Good article. Thank you very much

    Comment by Mohan Sharma — September 21, 2011 @ 8:47 am

  15. @Mohan Sharma :- You are welcome hope my post helps you

    Comment by yasserzaid — September 24, 2011 @ 2:56 pm

  16. [...] Handling Empty Data in DataList control Oct 14th, 2011 Leave a comment | Trackback ReadabilityHandling Empty Data in DataList controlHan­dling Empty Data in DataList control [...]

    Pingback by Jagdeep Kaur » Handling Empty Data in DataList control — October 14, 2011 @ 4:37 pm

  17. Thanks alot.It’s working correctly.

    Comment by Shafeeque — November 15, 2011 @ 12:01 pm

  18. @Shafeeque :- You are welcome … Good Luck

    Comment by yasserzaid — December 3, 2011 @ 7:06 pm

  19. thnks dude

    Comment by kaps — December 8, 2011 @ 9:27 am

  20. thnx

    Comment by kaps — December 8, 2011 @ 9:42 am

  21. @kaps :- You are welcome hope my post helps you

    Comment by yasserzaid — December 19, 2011 @ 7:16 pm

  22. Thanks . Its very helpful

    Comment by shamna Sankar — February 14, 2012 @ 4:41 am

  23. @shamna :- You are welcome ;)

    Comment by yasserzaid — February 14, 2012 @ 2:19 pm

  24. Thank you!!

    Comment by Yogi — April 19, 2012 @ 11:39 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.