jQuery and ASP.NET

February 23, 2010

Display an Image when the GridView has no data




I recently answered a question on the forum where a user wanted to display an image when the GridView returns empty data. Now you must be already be familiar with the GridView’s EmptyDataText property which displays a message to the user when there are no results returned from the GridView control’s data source.

Now instead of a text message, if you need to display an image or any HTML/ASP.NET control, you can use the EmptyDataTemplate. In this snippet below, we are using the image control in the <EmptyDataTemplate> to display an image.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1"
ShowFooter="true" AllowPaging="True" AllowSorting="True"
>

<
EmptyDataTemplate>
<
asp:Image id="imgOne"
ImageUrl="~/images/Emptydata.jpg"
AlternateText="No results"
runat="server"/>
</
EmptyDataTemplate>


'Like' us on our FaceBook page if you find this blog useful. Thanks!


Did you like this post?
kick it on DotNetKicks.com Save on Delicious
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

1 Response to "Display an Image when the GridView has no data"
  1. Ramesh said...
    July 6, 2010 5:37 PM

    Display an Image when the GridView has no data

    That was a good post, but I wanted it on other way. Suppose we are not using sqldatasource control and binding a datatable to it. If datatable doesn't have any rows, the grid is not display neither the EmptyDataText.

    I appreciate any solution for this

 

Copyright © 2009-2011 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions