空的Repeater控件的默认文本 [英] Default text for empty Repeater control

查看:39
本文介绍了空的Repeater控件的默认文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用VS 2008,我有一个Repeater控件:

Using VS 2008, I have a Repeater control:

<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>&nbsp;&nbsp;&nbsp;&nbsp;
            </td>
            <td style="width:110px">
              <asp:Label ID="storeLbl" runat="server" Text='<%# Bind("Name") %>'>
              </asp:Label>&nbsp;&nbsp;
            </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>

现在,如果数据源没有从数据库返回任何项目,我想显示一个默认文本,例如找不到存储".到目前为止,由于 EmptyDataText 属性,我主要使用 GridView 来解决问题.

Now I would like to display a default text like "No stores found" if data source returns no items from database. Until now I have mostly used GridView where I didn't have problems because of the EmptyDataText attribute.

推荐答案

您可以解决以下问题: Repeater 不支持通过使用 FooterTemplate内置的方法来完成您的工作 OnItemDataBound 事件结合使用,并仅在数据源不返回任何项目时显示页脚.

You could workaround the fact that Repeater does not support a inbuilt way to accomplish what you are doing by using the FooterTemplate in conjunction with the OnItemDataBound event and showing the footer only when the data source returns no items.

有关如何执行此操作的示例,请参见:

Examples on how you can do this can be found at:

在ASP.NET转发器控件中处理空数据

如何显示为空ASP.NET Repeater控件中的模板?

这篇关于空的Repeater控件的默认文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆