Question

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?

Était-ce utile?

La solution

I feel like an idiot.

It turns out that there was nothing wrong with my code.

Subnodes were not being processed because the repeaters were not rendered. My code includes logic that hides code (and, subsequently, does not process repeaters) if nodes don't have any values.

Nevertheless, I'm keeping this question here instead of deleting it for future reference.

Sorry for wasting everyone's bandwidth -- we now return you to your regularly-scheduled spam.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top