Render empty repeater

可紊 提交于 2019-12-05 04:09:00
Saurabh

In the <FooterTemplate>, add a Label with some empty data text and set its visible property to false.

<FooterTemplate>
<table>
 <tr>
 <td>
 <asp:Label ID="lblEmptyData"
        Text="No Data To Display" runat="server" Visible="false">
 </asp:Label>
 </td>
 </tr>
 </table>           
 </FooterTemplate>

Now check the the data while binding repeater, if no rows return then make label visible otherwise no action.

More details here.

as @Saurabh said, use <FooterTemplate> add a Label with specifying your message in the Text property and set its visible property to false like this:

<FooterTemplate>
        <%-- Label used for showing Error Message --%>
        <asp:Label ID="ErrorMessage" runat="server" Text="Sorry!!" Visible="false">
        </asp:Label>
    </FooterTemplate>

Then in the code-behind use the following logic; if there is no data, show the message, otherwise, show the data as following:

protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    Repeater rpt = sender as Repeater; // Get the Repeater control object.

    // If the Repeater contains no data.
    if (rpt != null && rpt.Items.Count < 1)
    {
        if (e.Item.ItemType == ListItemType.Footer)
        {
            // Show the Error Label (if no data is present).
            Label ErrorMessage = e.Item.FindControl("ErrorMessage") as Label;
            if (ErrorMessage != null)
            {
                ErrorMessage.Visible = true;
            }
        }
    }
}
alireza alimardan
<asp:Repeater ID="rptList" runat="server" DataSourceID="odsList">  
    ...
    <FooterTemplate>  
        <%if (rptList.Items.Count == 0)  
          { %>  
          **Your message**  
        <%} %>  
    </FooterTemplate>  
</asp:Repeater>

Try this

protected bool IsDataEmpty     
  {    
       get    
       {    
           ICollection list = Repeater1.DataSource as ICollection;    
           return list.Count == 0 ? true : false;    
       }    
  }

In Markup :

<table width="80%">   
     <tr runat="server"

         visible='<%# IsDataEmpty %>'>    
         <td>    
             There is no data to display    
           </td>    
     </tr>

for step by step follow the link :Link

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!