0

I'm trying to solve a problem with controls in a nested repeater not being processed.

First, let me illustrate my scenario. I have XML that looks like this:

<ParentNode>
    <SubNode>
        <SomeNode></SomeNode>
        <SomeNode></SomeNode>
        <SomeNode></SomeNode>
    </SubNode>
    <SubNode>
        <SomeNode></SomeNode>
        <SomeNode></SomeNode>
        <SomeNode></SomeNode>
    </SubNode>
    <SubNode>
        <SomeNode></SomeNode>
        <SomeNode></SomeNode>
        <SomeNode></SomeNode>
    </SubNode>
</ParentNode>

To process this, I have nested repeaters that look like this:

<!-- note: XPath for DataSource = "/ParentNode/SubNode" -->
<asp:Repeater ID="ProcessSubNode" runat="server">
    <ItemTemplate>
        <!-- note: XPath for DataSource = "/ParentNode/SubNode/SomeNode" -->
        <asp:Repeater ID=ProcessSomeNode" runat="server">
            <ItemTemplate>
                <!-- some miscellaneous web forms code goes here -->
            </ItemTemplate>
        </asp:Repeater>
    </ItemTemplate>
</asp:Repeater>

I have code-behind processing for saving my data that looks like this:

Protected Sub OnSave()
    For Each itemSubNode As RepeaterItem In Me.ProcessSubNode.Items
        For Each itemSomeNode As RepeaterItem In CType(itemSubNode.FindControl("ProcessSomeNode"), Repeater).Items
            ' some processing code goes here
        Next
    Next
End Sub

Here's my problem: My OnSave code illustrated above works just fine on its first pass through the first <SubNode> nodes (it processes all the <SomeNode> nodes with no problem).

However, on its next pass through the second (and subsequent) set of <SubNode> nodes, it does not see the <SomeNode> nodes inside of it at all. The For Each loop skips to the next <SubNode> as though the <SubNode> nodes don't even exist.

I can't find anything that explains how to fix this. Does anyone have any insight?

4

1 回答 1

0

我觉得自己像个白痴。

事实证明,我的代码没有任何问题。

由于未呈现中继器,因此未处理子节点。如果节点没有任何值,我的代码包含隐藏代码(并且随后不处理中继器)的逻辑。

不过,我将这个问题保留在这里,而不是删除它以供将来参考。

很抱歉浪费了大家的带宽 - 我们现在将您返回到您定期安排的垃圾邮件。

于 2014-03-20T19:19:50.303 回答