1

リピーターを使用してリストを表示すると、リストが空を返す場合、テーブルは空白になるので、「テーブルは空です」というメッセージを表示しましたが、テーブルヘッダーの可視性をfalseに設定したいのですが、 tis?

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." />

次にOnPreRender、Webフォームで、次のコードを記述します。

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 に答える