使用VS 2008,我有一个中继器控件:

<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>

现在,如果数据源没有从数据库返回任何项,我想显示一个默认文本,如"No stores found".到目前为止,我主要使用GridView,因为EmptyDataText属性,我没有问题.

推荐答案

通过将FooterTemplateOnItemDataBound事件结合使用,并且仅当数据源不返回任何项时才显示页脚,可以解决Repeater不支持以内置方式完成所做工作的问题.

有关如何做到这一点的示例,请访问:

Handling Empty Data in an ASP.NET Repeater control

How to show Empty Template in ASP.NET Repeater control?

Asp.net相关问答推荐

任何人都有解决 Internet Explorer 上剩余 n 项问题的 idea 吗?

更改 GridView 中列的标题文本

iframe.readyState 在 chrome 中不起作用

IIS 将旧用户名返回到我的应用程序

更新到 ASP.NET Core 2.0 - 包与 netcoreapp2.0 不兼容

ASP.NET-MVC 中的表单发布上的 FormCollection 为空

用于 ASP.NET 的 System.Drawing 的替代品?

ASP.net 页面在导入语句上出现错误,但我确实有参考?

在使用网络服务器加载它们之前,如何编译 Asp.Net Aspx 页面?

部署后网站需要强制刷新

排序下拉列表? - C#,ASP.NET

MVC5 身份验证中的......与主域之间的信任关系失败

修改 web.config 时如何防止 ASP.NET 应用程序重新启动?

这个rendersection的代码是什么意思?

将新行添加到数据表的顶部

导航到本地 IIS Express 时,Chrome 会返回错误请求 - 请求太长

模型是否包含字段而不将其添加到数据库中?

在 Asp.Net Core 中动态更改连接字符串

可以在不 destruct 站点的情况下将 MIME 类型添加到 web.config 吗?

ModelClientValidationRule 冲突