(转)Repeater在无数据记录时显示暂无数据

方法就是在FooterTemplate加个Label并根据repeater.Items.Count判断是否有记录。关键代码如下:

<FooterTemplate>
    <asp:Label ID="lblEmpty" Text="无记录.." runat="server"  Visible='<%#bool.Parse((rptRecord.Items.Count==0).ToString())%>'></asp:Label> 
</FooterTemplate> 

示例代码:

<table class="r_line" cellpadding="3" cellspacing="1" width="100%">
    <tr class="r_title">
        <td>编号</td>
    </tr>
<asp:Repeater ID="rptRecord" runat="server">
    <ItemTemplate>
        <tr style='background-color:<%#(Container.ItemIndex%2==0)?"#fff":"#eee"%>'>
            <td><a href='Detail.aspx?PID=<%=Request.QueryString["PID"] %>&did=<%#Eval("PID") %>'><%#Eval("PID") %></a></td>
        </tr>
    </ItemTemplate>
    <FooterTemplate>   
        <tr class="r_bg">
            <td>
<asp:Label ID="lblEmpty" Text="无记录.." runat="server"  Visible='<%#bool.Parse((rptRecord.Items.Count==0).ToString())%>'></asp:Label> 
                </td>
            </tr>
    </FooterTemplate>  
</asp:Repeater>
</table>
原文地址:https://www.cnblogs.com/wanshutao/p/4291860.html