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>

 

左侧导航栏代码

posted @ 2012-02-08 09:45  eva.xiao  阅读(1605)  评论(0编辑  收藏  举报