Overblog Follow this blog
Edit post Administration Create my blog
Balavardhan Reddy Narani

Display an Image or Custom message for EmptyData in an ASP.NET GridView

August 5 2009 , Written by Balavardhan Reddy Published on #ASP.Net

Some times we will get Empty Dataset or Data table from the Database to bind the Gridview. At this point of time we can  display Custom message or an Image in GridView .

The GridView’s EmptyDataText property allows you display a message when there are no results returned from the GridView control’s data source.



Ex:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound">
    <Columns>
        <asp:TemplateField>
            <HeaderTemplate>
                <asp:CheckBox ID="cb_chkall" runat="server" />
            </HeaderTemplate>
            <ItemTemplate>
                 <asp:CheckBox ID="cb_active" runat="server" />
            </ItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField>
             <ItemTemplate>
                  <asp:Label ID="lbl_msg" runat="server" text="Msg"></asp:Label>
              </ItemTemplate>
          </asp:TemplateField>
        
<asp:TemplateField>
             <ItemTemplate>
                  <asp:Label ID="lbl_Name" runat="server" text=
'<%#Eval("Name")%>'>                   </asp:Label>
              </ItemTemplate>
          </asp:TemplateField>
    </Columns>
    <EmptyDataTemplate>
       <Asp:Image id="img_nodata" AlternateText="No Records Found" runat="server"
        ImageURl="Images/nodata.jpg" />
    </EmptyDataTemplate>
</asp:GridView>





By the Above smaple, if there is no records in your Data Source, It can display nodata.Jpg image inside the GridView control




--

Share this post

Repost 0

Comment on this post

Custom Research Paper 12/01/2009 09:03


Many institutions limit access to their online information. Making this information available will be an asset to all.

Custom Research Papers


Custom Research Paper 12/01/2009 08:59


Many institutions limit access to their online information. Making this information available will be an asset to all.

Custom Research Papers