2

我在另一个中继器的 ItemTemplate 中有一个嵌套中继器。我向转发器添加了一个 OnItemDataBound 函数,但代码不执行

aspx

<asp:Repeater ID="rptComponents" runat="server" OnItemDataBound="rptComponents_ItemDataBound">
            <HeaderTemplate>
            </HeaderTemplate>
            <ItemTemplate>
                <div class="row-fluid">
                    <div class="span2">
                        <asp:Repeater ID="rptComponentsImages" runat="server" OnItemDataBound="rptComponentsImages_ItemDataBound">
                            <HeaderTemplate>
                                <ul class="bxslider">
                            </HeaderTemplate>
                            <ItemTemplate>
                                <li>
                                    <img src="<%# Eval("CKCI_File")%>" /></li>
                            </ItemTemplate>
                            <FooterTemplate>
                                <li runat="server" id="liNoData" visible="false">
                                    <img src="http://placehold.it/132&text=No image" alt=""></li>
                                </ul>
                            </FooterTemplate>
                        </asp:Repeater>
                    </div>
                    <div class="">
                        <%# Eval("CKC_Title") %>
                    </div>


                </div>
            </ItemTemplate>
            <FooterTemplate>
            </FooterTemplate>
        </asp:Repeater>

编码

protected void rptComponents_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {

            ClutchKitComponent rd = (ClutchKitComponent)e.Item.DataItem;

            List<ClutchComponentImage> kitComponentImages = (List<ClutchComponentImage>)rd.images;

            Repeater rt = (Repeater)e.Item.FindControl("rptComponentsImages");
            rt.DataSource = kitComponentImages;
            rt.DataBind();

        }
    }

    protected void rptComponentsImages_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Repeater rt = (Repeater)sender;
        if (rt.Items.Count < 1)
        {
            if (e.Item.ItemType == ListItemType.Footer)
            {
                e.Item.FindControl("liNoData").Visible = true;
            }
        }
    }

第二个功能不执行

4

2 回答 2

1

我在其中一个列表上有一个空值,所以它抛出了一个我没有抓住的前任。即使没有数据,也会触发 OnItemDataBound。

于 2013-02-27T13:36:08.063 回答
0

你有里面的中继器的 ItemDataBound 事件吗?您是否尝试在 ItemCreated 或第一个 ItemDataBound 事件中添加该事件?

rt.ItemDataBound += new RepeaterItemEventHandler(rt_ItemDataBound);

检查此链接以获取嵌套中继器。http://www.codeproject.com/Articles/20230/Nesting-Data-bound-Repeater-Controls-in-ASP-Net

于 2013-02-27T14:17:18.427 回答