Join us at Facebook
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>


Bookmark this link on del.icio.us (saved by 0 users)

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

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 2010 All Rights Reserved DevCurry.com by Suprotim Agarwal