c# - OnItemDataBound 不会在嵌套的 Repeater 上触发?

标签 c# asp.net

我在另一个 Repeater 的 ItemTemplate 中有一个嵌套的 Repeater。 我向转发器添加了一个 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;
            }
        }
    }

第二个函数不执行

最佳答案

我在其中一个列表中有一个空值,所以它抛出了一个我没有捕捉到的 ex。 即使没有数据,OnItemDataBound 也会被触发。

关于c# - OnItemDataBound 不会在嵌套的 Repeater 上触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15112593/

相关文章:

c# - 如何在 ODataQueryOptions 上启用 $expand 和 $select?

c# - 隐藏和显示标签和按钮

c# - 在 ASP.NET MVC 单元测试中使用 Moq 模拟函数时无法返回非空字符串

c# - 如何在 asp.net TreeView 中的树节点中存储数组数据

c# - Entity Framework 从插入中排除字段

c# - 如何更改应用程序中每个控件的属性

c# - XUnit 如何对业务对象进行单元测试,我应该模拟所有内容吗?

c# - Microsoft MessageQueue Formatter 属性始终为空

javascript - 如何从本地驱动器打开文件 - Angular 4

asp.net - 不同控制事件的客户端验证