1

使用中继器显示列表,如果列表返回空表将为空,所以我显示了一条消息“表为空”,但我也想将表头的可见性设置为 false,是否有一个属性是吗?

repeater.header 什么的?

谢谢


编辑:对于那些不能在黑暗中编程的人

<asp:Repeater id="rptSelectedUtilities" runat="server">
    <HeaderTemplate>
        <table class="detailstable FadeOutOnEdit">
            <tr>   
                <th style="width:200px;">Utility</th>    
                <th style="width:200px;">Contacted</th>   
                <th style="width:200px;">Comment</th>    
            </tr>
    </HeaderTemplate>
    <ItemTemplate>
            <tr>
                <th style="width:200px;"><%# Eval("Name") %></th>
                <th style="width:200px;"><asp:CheckBox ID="chkMyCheck" runat="server" Checked='<%# Convert.ToBoolean(Eval("Checked")) %>'/></th>   
                <th style="width:200px;"><%# Eval("Comment") %></th>  
            </tr>
            <asp:Label id="labelTableEmpty" runat="server" Text="There are currently no items in this table." />
    </ItemTemplate>
    <FooterTemplate>
            <asp:Label id="labelTableEmpty" runat="server" Text="There are currently no items in this table." />
        </table>
    </FooterTemplate>
</asp:Repeater>

谢谢你的帮助

4

1 回答 1

2

好吧,让我们稍微改变一下。我们将使中继器整体不可见,然后在标记中添加另一个标签,并在必要时使其可见。用这个替换转发器代码:

<asp:Repeater id="rptSelectedUtilities" runat="server">
    <HeaderTemplate>
        <table class="detailstable FadeOutOnEdit">
            <tr>   
                <th style="width:200px;">Utility</th>    
                <th style="width:200px;">Contacted</th>   
                <th style="width:200px;">Comment</th>    
            </tr>
    </HeaderTemplate>
    <ItemTemplate>
            <tr>
                <th style="width:200px;"><%# Eval("Name") %></th>
                <th style="width:200px;"><asp:CheckBox ID="chkMyCheck" runat="server" Checked='<%# Convert.ToBoolean(Eval("Checked")) %>'/></th>   
                <th style="width:200px;"><%# Eval("Comment") %></th>  
            </tr>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>

然后在中继器之后添加这个(你当然可以改变措辞):

<asp:Label id="labelTableEmpty" runat="server" Text="There are currently no items in this table." />

然后在OnPreRenderweb 表单中,我们将编写一些代码:

protected override void OnPreRender(EventArgs e)
{
    if (rptSelectedUtilities.Items.Count == 0)
    {
        rptSelectedUtilities.Visislbe = false;
        labelTableEmpty.Visible = true;
    }
    else
    {
        rptSelectedUtilities.Visislbe = true;
        labelTableEmpty.Visible = false;
    }
}
于 2013-03-07T12:15:38.973 回答