DataList在无数据记录时显示类似GridView空模板(EmptyDataTemplate)

在FooterTemplate加个Label并根据repeater.Items.Count判断是否有记录。HTML代码:

<FooterTemplate>
       
<asp:Label ID="lblEmpty" Text="No data recprd exist !" runat="server"  

Visible='<%#bool.Parse((DataList1.Items.Count==0).ToString())%>'></asp:Label> 
</FooterTemplate> 

 Sample:

其中: <a href='<%#Eval("ID","DeviceDetail.aspx?DeviceID={0}") %>'>是根据参数超链接到另一个页面。

         <img alt="" width="120px" src='<%#Eval("DevicePicture") %>' /><br />是读取数据库中的图片地址,并显示相应图片。

 

HTML Source
 <asp:DataList ID="dlDevice" runat="server" RepeatColumns="5" RepeatDirection="Horizontal">
<FooterTemplate>
<div style="text-align: center; color: Red; font-weight: bold; padding-left:10px;">
<asp:Label ID="lblEmpty" Text="No data record exist ..." runat="server" Visible='<%#bool.Parse((dlDevice.Items.Count==0).ToString())%>'></asp:Label>
</div>
</FooterTemplate>
<ItemTemplate>
<table style="margin-left: 20px; margin-top: 10px; padding: 20px; text-align: center;border: 1px solid #007795;">
<tr>
<td>
<a href='<%#Eval("ID","DeviceDetail.aspx?DeviceID={0}") %>'> <img alt="" width="120px" src='<%#Eval("DevicePicture") %>' /><br />
<span><%#Eval("DeviceName") %></span> </a>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>

 

左侧导航栏代码

转载于:https://www.cnblogs.com/eva_2010/archive/2012/02/08/2342200.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值