如何在另一个中继器中找到中继器

发布于 2024-12-03 12:12:29 字数 1115 浏览 3 评论 0原文

我想在另一个中继器中找到中继器。但我找不到。我的代码是

<asp:Repeater ID="rep_test" runat="server">
     <ItemTemplate>
           <div id='h<%# DataBinder.Eval(Container, "ItemIndex") %>' class="header" onclick='ToggleDisplay(<%# DataBinder.Eval(Container, "ItemIndex") %>);'>
                    <%#DataBinder.Eval(Container.DataItem, "ID")%>
           </div>
           <div id='d<%# DataBinder.Eval(Container, "ItemIndex") %>' class="details">
           <asp:Repeater ID="rep_hello" runat="server">
                <ItemTemplate>
                    <%#DataBinder.Eval(Container.DataItem, "batchid")%><br />
                    <%#DataBinder.Eval(Container.DataItem, "ts")%><br />
                </ItemTemplate>
           </asp:Repeater>
                <%--    <%#DataBinder.Eval(Container.DataItem, "batchid")%><br />
                    <%#DataBinder.Eval(Container.DataItem, "ts")%><br />--%>
            </div>
     </ItemTemplate>
</asp:Repeater>

I want to find repeater inside the another repeater. But i m not able to find. My code is

<asp:Repeater ID="rep_test" runat="server">
     <ItemTemplate>
           <div id='h<%# DataBinder.Eval(Container, "ItemIndex") %>' class="header" onclick='ToggleDisplay(<%# DataBinder.Eval(Container, "ItemIndex") %>);'>
                    <%#DataBinder.Eval(Container.DataItem, "ID")%>
           </div>
           <div id='d<%# DataBinder.Eval(Container, "ItemIndex") %>' class="details">
           <asp:Repeater ID="rep_hello" runat="server">
                <ItemTemplate>
                    <%#DataBinder.Eval(Container.DataItem, "batchid")%><br />
                    <%#DataBinder.Eval(Container.DataItem, "ts")%><br />
                </ItemTemplate>
           </asp:Repeater>
                <%--    <%#DataBinder.Eval(Container.DataItem, "batchid")%><br />
                    <%#DataBinder.Eval(Container.DataItem, "ts")%><br />--%>
            </div>
     </ItemTemplate>
</asp:Repeater>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

扮仙女 2024-12-10 12:12:29

如果将中继器放入另一个中继器的项目模板中,则意味着主中继器 (rep_test) 的每个项目都会在其中包含一个中继器 (rep_hello)。所以你实际上需要在repeaterItem中找到repeater。您可以像这样迭代所有嵌套的转发器:

foreach (RepeaterItem item in rep_test)
        Repeater rptr = (Repeater)item.FindControl("rep_hello");

If you put a repeater inside an item template of another repeater that means that every item of the main repeater (rep_test) will have a repeater inside it (rep_hello). So you actually need to find the repeater inside a repeaterItem. You can iterate trough all the nested repeaters like this:

foreach (RepeaterItem item in rep_test)
        Repeater rptr = (Repeater)item.FindControl("rep_hello");
夏雨凉 2024-12-10 12:12:29

示例:

ItemDataBound 事件处理程序中:

protected void rep_test_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
  if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==  ListItemType.AlternatingItem)
  {
    (e.Item.FindControl("rep_hello") as Repeater).DataSource = YourOtherDataSource;      
  }
}

Example:

In ItemDataBound event handler:

protected void rep_test_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
  if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==  ListItemType.AlternatingItem)
  {
    (e.Item.FindControl("rep_hello") as Repeater).DataSource = YourOtherDataSource;      
  }
}
萌︼了一个春 2024-12-10 12:12:29

您可以尝试使用.FindControl()。在VB中,它会是这样的

Dim rpt as Repeater = rep_test.FindControl("rep_hello")

You can try using .FindControl(). In VB, it would be something like

Dim rpt as Repeater = rep_test.FindControl("rep_hello")
勿忘心安 2024-12-10 12:12:29

通常当我看到这种事情时,你想在所有内部中继器上执行一些事件。我通常做的是在 ItemDataBound 事件中处理这种事情。

将 OnItemDataBound 属性添加到您的 Repeater。

<asp:Repeater ID="rep_test" runat="server" 
OnItemDataBound="rep_test_ItemDataBound">

然后在后端添加一个处理程序,并调用 FindControl。

protected void rptBasket_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || 
        e.Item.ItemType == ListItemType.AlternatingItem)
    {
         Repeater innerRepeater = (Repeater)e.Item.FindControl("rep_hello");
         // Now your have your repeater...do what you want with it.
    }
}

Usually when I see this kind of thing, you want to perform some event on all of the inner repeaters. What I usually do is handle this kind of thing inside the ItemDataBound event.

Add an OnItemDataBound attribute to your Repeater.

<asp:Repeater ID="rep_test" runat="server" 
OnItemDataBound="rep_test_ItemDataBound">

Then in the back end, add a handler, with a FindControl call.

protected void rptBasket_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || 
        e.Item.ItemType == ListItemType.AlternatingItem)
    {
         Repeater innerRepeater = (Repeater)e.Item.FindControl("rep_hello");
         // Now your have your repeater...do what you want with it.
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文