查找位于另一个中继器内的中继器

发布于 2025-01-03 14:04:28 字数 2797 浏览 0 评论 0原文

好吧,我的问题是我有三个中继器。在那个中继器中,我有另一个中继器,第二个中继器中有第三个。两者之间还有更多内容,但不相关。 HTML 下面是我的 VB 代码。我的问题是 rptCrashPercentageAvg 没有回复。 rptCrashStatsDisplay 如何访问 rptCrashPercentageAvg?

<asp:Repeater ID="rptCrashStatsDisplay" runat="server">
        <ItemTemplate>
            <asp:Repeater ID="rptCrashPercentage" runat="server">
                <ItemTemplate>
                    <tr class="statsRowA">
                        <td class="emphasis" style="padding-left: 20px">
                            <%# DataBinder.Eval(Container.DataItem,"CRASH_TYPE_DESC") %>:
                        </td>
                        <td style="padding-left: 5px">
                            <%--background-color: <%# Iif(DataBinder.Eval(Container.DataItem,"CRASH_TYPE_PERCENT")>DataBinder.Eval(Container.DataItem,"COUNT(*)"), "red", "null") %>"--%>
                            <%#String.Format("{0:N1}", DataBinder.Eval(Container.DataItem, "CRASH_TYPE_PERCENT"))%>
                            %
                        </td>
                        <asp:Repeater ID="rptCrashPercentageAvg" runat="server">
                            <ItemTemplate>
                                <td style="padding-left: 5px">
                                    <%#String.Format("{0:N1}", DataBinder.Eval(Container.DataItem, "AVG_VAL"))%>
                                    %
                                </td>
                            </ItemTemplate>
                        </asp:Repeater>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
       </ItemTemplate>
    </asp:Repeater>
Private Sub rptCrashStatsDisplay_ItemDataBound(ByVal sender As System.Object, _
ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptCrashStatsDisplay.ItemDataBound
    Dim dv As DataRowView = CType(e.Item.DataItem, DataRowView)
    If Not IsNothing(dv) Then
        Dim rptCrashPercentage As Repeater = CType(e.Item.FindControl("rptCrashPercentage"), Repeater)
        Dim view As DataView = dv.CreateChildView("statRel1")
        If (view.Count > 0) Then
            rptCrashPercentage.DataSource = view
            rptCrashPercentage.DataBind()
        End If
        Dim rptCrashPercentageAvg As Repeater = CType(e.Item.FindControl("rptCrashPercentageAvg"), Repeater)
        Dim viewAvg As DataView = dv.CreateChildView("statRel2")
        If (viewAvg.Count > 0) Then
            rptCrashPercentageAvg.DataSource = viewAvg
            rptCrashPercentageAvg.DataBind()
        End If
    End If
End Sub

Ok so my issue is I have three repeaters. Within that repeater I have another repeater and a third one in the second. There is more in between but that's not relevant. Below the HTML is my VB code. My issue is that rptCrashPercentageAvg reutrns Nothing. How can rptCrashStatsDisplay access rptCrashPercentageAvg?

<asp:Repeater ID="rptCrashStatsDisplay" runat="server">
        <ItemTemplate>
            <asp:Repeater ID="rptCrashPercentage" runat="server">
                <ItemTemplate>
                    <tr class="statsRowA">
                        <td class="emphasis" style="padding-left: 20px">
                            <%# DataBinder.Eval(Container.DataItem,"CRASH_TYPE_DESC") %>:
                        </td>
                        <td style="padding-left: 5px">
                            <%--background-color: <%# Iif(DataBinder.Eval(Container.DataItem,"CRASH_TYPE_PERCENT")>DataBinder.Eval(Container.DataItem,"COUNT(*)"), "red", "null") %>"--%>
                            <%#String.Format("{0:N1}", DataBinder.Eval(Container.DataItem, "CRASH_TYPE_PERCENT"))%>
                            %
                        </td>
                        <asp:Repeater ID="rptCrashPercentageAvg" runat="server">
                            <ItemTemplate>
                                <td style="padding-left: 5px">
                                    <%#String.Format("{0:N1}", DataBinder.Eval(Container.DataItem, "AVG_VAL"))%>
                                    %
                                </td>
                            </ItemTemplate>
                        </asp:Repeater>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
       </ItemTemplate>
    </asp:Repeater>
Private Sub rptCrashStatsDisplay_ItemDataBound(ByVal sender As System.Object, _
ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptCrashStatsDisplay.ItemDataBound
    Dim dv As DataRowView = CType(e.Item.DataItem, DataRowView)
    If Not IsNothing(dv) Then
        Dim rptCrashPercentage As Repeater = CType(e.Item.FindControl("rptCrashPercentage"), Repeater)
        Dim view As DataView = dv.CreateChildView("statRel1")
        If (view.Count > 0) Then
            rptCrashPercentage.DataSource = view
            rptCrashPercentage.DataBind()
        End If
        Dim rptCrashPercentageAvg As Repeater = CType(e.Item.FindControl("rptCrashPercentageAvg"), Repeater)
        Dim viewAvg As DataView = dv.CreateChildView("statRel2")
        If (viewAvg.Count > 0) Then
            rptCrashPercentageAvg.DataSource = viewAvg
            rptCrashPercentageAvg.DataBind()
        End If
    End If
End Sub

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

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

发布评论

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

评论(1

半山落雨半山空 2025-01-10 14:04:28

我会尝试确保您在正确的位置寻找它。它会在中继器的标头中查找控件,因为它在那里找不到它,所以当您第一次尝试使用它时,它将什么也没有。

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
    Dim rptCrashPercentageAvg As Repeater = CType(e.Item.FindControl("rptCrashPercentageAvg"), Repeater)
    'Shouldn't be "nothing" here.
End If

否则,您可以尝试一种效率更低的方法:

Dim rptCrashPercentageAvg As Repeater = CType(e.Item.FindControl("rptCrashPercentageAvg"), Repeater)
If rptCrashPercentageAvg IsNot Nothing Then
    Dim viewAvg As DataView = dv.CreateChildView("statRel2")
    If (viewAvg.Count > 0) Then
       rptCrashPercentageAvg.DataSource = viewAvg
       rptCrashPercentageAvg.DataBind()
    End If
End If

编辑:此外,由于它实际上是一个中继器,因此您不需要 CType。

I would try making sure you're looking for it in the correct place. It'll look in your repeater's Header for the control and since it won't find it there, it'll be Nothing the first time you try and use it.

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
    Dim rptCrashPercentageAvg As Repeater = CType(e.Item.FindControl("rptCrashPercentageAvg"), Repeater)
    'Shouldn't be "nothing" here.
End If

Otherwise you could try a more inefficient method:

Dim rptCrashPercentageAvg As Repeater = CType(e.Item.FindControl("rptCrashPercentageAvg"), Repeater)
If rptCrashPercentageAvg IsNot Nothing Then
    Dim viewAvg As DataView = dv.CreateChildView("statRel2")
    If (viewAvg.Count > 0) Then
       rptCrashPercentageAvg.DataSource = viewAvg
       rptCrashPercentageAvg.DataBind()
    End If
End If

Edit: Also, since it actually is a repeater, you shouldn't need the CType.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文