隐藏的孩子和家长转发的时候孩子中继器是空的 [英] Hide child and parent repeater when child repeater is empty

查看:185
本文介绍了隐藏的孩子和家长转发的时候孩子中继器是空的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于在ASP.net中继器的问题。

I have a question regarding repeaters in ASP.net

我有2个中继器嵌套。结果
我想隐藏的双方父母,每当孩子中继持有任何项目的子中继器。
与他们的孩子的项目每一个家长都给人独特的类,如阶级=childlist_1。

I have 2 repeaters nested.
I would like to hide both the parent and the child repeater whenever the child repeater holds no items. Each parent with their child items are giving unique classes like 'class="childlist_1"'.

ASCX文件:

<asp:Repeater ID="ParentRepeater" runat="server">
<ItemTemplate>
    <ul class="Mainlist">
       <li>
        <h3 class="selected"><a href="#">List 1</a></h3>
        <ul id="DomainList" class="child-items" runat="server">
            <asp:Repeater ID="ChildRepeater" runat="server">
                <ItemTemplate><li><a href="#">Link to child item</a></li></ItemTemplate>
            </asp:Repeater>
        </ul>
        </li>
    </ul>
</ItemTemplate>
</asp:Repeater>

什么是最好的解决方案呢?

What is the best solution for this?

在此先感谢!

推荐答案

您可以做到这一点<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemdatabound%28v=vs.110%29.aspx\"相对=nofollow>的ItemDataBound 事件

protected void ParentRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item)
    {
        // code that binds ChildRepeater
        .....

        // check if ChildRepeater has no items
        if (((Repeater)e.Item.FindControl("ChildRepeater")).Items.Count == 0)
        {
            e.Item.Visible = false;
        }
    }
}

这篇关于隐藏的孩子和家长转发的时候孩子中继器是空的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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