将转发器中的标头设置为visible.false

时间:2013-03-07 11:30:49

标签: asp.net header repeater

使用转发器显示列表,如果列表返回空,则表将为空,因此我显示了一条消息'table is empty'但我还想将表头的可见性设置为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>

感谢您的帮助

1 个答案:

答案 0 :(得分: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." />

然后在网络表单的OnPreRender中,我们将编写一些代码:

protected override void OnPreRender(EventArgs e)
{
    if (rptSelectedUtilities.Items.Count == 0)
    {
        rptSelectedUtilities.Visislbe = false;
        labelTableEmpty.Visible = true;
    }
    else
    {
        rptSelectedUtilities.Visislbe = true;
        labelTableEmpty.Visible = false;
    }
}