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/suizhikuo/p/4962033.html