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
4

1 回答 1

2

我会尝试确保您在正确的位置寻找它。它会在你的转发器的标题中查找控件,因为它不会在那里找到它,所以当你第一次尝试使用它时它会是 Nothing。

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。

于 2012-02-07T22:46:06.523 回答