使用 VS 2008,我有一个 Repeater 控件:
<asp:Repeater runat="server" ID="storesRep" DataSourceID="storeSqlDataSource"
OnItemDataBound="StoresRep_ItemDataBound">
<ItemTemplate>
<table style="padding:0px">
<tr>
<td style="width:200px"><asp:Label ID="infoLbl" runat="server">
Choose stores for upload:</asp:Label>
</td>
<td style="width:110px">
<asp:Label ID="storeLbl" runat="server" Text='<%# Bind("Name") %>'>
</asp:Label>
</td>
<td><asp:CheckBox runat="server" ID="storeCheck" /></td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="storeSqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:someConnectionString %>"
SelectCommand="SELECT [StoreId], [Name] FROM [Store] Order By [Name]">
</asp:SqlDataSource>
现在,如果数据源未从数据库返回任何项目,我想显示默认文本,例如“未找到商店”。到目前为止我主要使用的是GridView
我没有遇到问题,因为EmptyDataText
属性。
若昂的回答甚至可以简化。在页脚中,不要将默认项的visible-property设置为false,而是使用以下表达式:
<FooterTemplate>
<asp:Label ID="defaultItem" runat="server"
Visible='<%# YourRepeater.Items.Count == 0 %>' Text="No items found" />
</FooterTemplate>
这样,就可以省掉后面的代码了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)