Question

I'd like to use nested repeaters that share the same XML datasource where the parent repeater passes down the datasource to the child repeater so it doesn't need to re-access the datasource for every dataitem in the parent repeater.

XPATH for Parent Repeater: "/AdpDeselection/Documents/Document[@type='A']/Funds/Fund[@cuspid='1234']"

What would I put for the DataSource attribute in the child Repeater in the code below?

I'd prefer not have to use an OnItemDataBound because I don't think it needs it but I guess I could be wrong.

    <asp:XmlDataSource ID="xdsCurrentFunds" runat="server" DataFile="~/App_Data/CustomApps/DeselectOptions.xml" />

    <asp:Repeater ID="rptCurrentFund" runat="server" OnItemDataBound="rptCurrentFund_ItemDataBound" DataSourceID="xdsCurrentFunds">
        <ItemTemplate>
            <div class="CurrentFund"><%# XPath("@name")%></div>
            <asp:HiddenField ID="hdnID" runat="server" Value='<%# XPath("@cuspid")%>' />
            <asp:Repeater ID="rptReplacementFunds" runat="server" DataSource='WHAT SHOULD I PUT HERE TO GET THE DATASOURCE?'>
                <ItemTemplate>
                    <div class="ReplacementFund"><%# XPath("@ticker")%></div>
                </ItemTemplate>
            </asp:Repeater>
        </ItemTemplate>
        <SeparatorTemplate>
            <br />
        </SeparatorTemplate>
    </asp:Repeater>

XML Structure...

<Deselection>
    <Documents>
        <Document type="A">
            <Funds>
                <Fund cuspid="1234" name="CURRENT FUND NUMBER ONE">
                    <ReplacementFunds>
                        <Fund ticker="ABCD" cuspid="56785678">FUND NUMBER ONE</Fund>
                        <Fund ticker="EFGH" cuspid="23452345">FUND NUMBER TWO</Fund>
                    </ReplacementFunds>
                </Fund>
                <Fund cuspid="2345" name="CURRENT FUND NUMBER ONE">
                    <ReplacementFunds>
                        <Fund ticker="HJKL" cuspid="56785678">FUND NUMBER THREE</Fund>
                        <Fund ticker="YUIO" cuspid="23452345">FUND NUMBER FOUR</Fund>
                    </ReplacementFunds>
                </Fund>
        </Document>
    </Documents>
</Deselection>
Was it helpful?

Solution

I actually found my answer after some more extensive digging. Here's the working code:

<asp:XmlDataSource ID="xdsCurrentFunds" runat="server" DataFile="~/App_Data/CustomApps/DeselectOptions.xml" />

<asp:Repeater ID="rptCurrentFund" runat="server" OnItemDataBound="rptCurrentFund_ItemDataBound" DataSourceID="xdsCurrentFunds">
    <ItemTemplate>
        <div class="CurrentFund"><%# XPath("@name")%></div>
        <asp:Repeater ID="rptReplacementFunds" runat="server" DataSource='<%# XPathSelect("ReplacementFunds/*") %>'>
            <ItemTemplate>
                <div class="ReplacementFund"><%# XPath("@ticker")%></div>
            </ItemTemplate>
        </asp:Repeater>
    </ItemTemplate>
    <SeparatorTemplate>
        <br />
    </SeparatorTemplate>
</asp:Repeater>

This works like a charm with no OnItemDataBound code required.

The secret sauce is the XPathSelect apparently.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top