如何使用单个 XMLDataSource 来使用嵌套中继器?

发布于 2024-11-04 18:02:34 字数 2247 浏览 1 评论 0原文

我想使用共享相同 XML 数据源的嵌套转发器,其中父转发器将数据源传递到子转发器,因此不需要重新访问父转发器中每个数据项的数据源。

父中继器的 XPATH:“/AdpDeselection/Documents/Document[@type='A']/Funds/Fund[@cuspid='1234']”

在下面的代码中,我将为子中继器中的 DataSource 属性放置什么?

我不想使用 OnItemDataBound,因为我认为它不需要它,但我想我可能是错的。

    <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 结构...

<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>

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>

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

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

发布评论

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

评论(1

黎夕旧梦 2024-11-11 18:02:34

经过更广泛的挖掘后,我实际上找到了答案。这是工作代码:

<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>

这就像一个魅力,不需要 OnItemDataBound 代码。

秘密武器显然是 XPathSelect

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.

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