gpt4 book ai didi

.net - 如何使用单个 XMLDataSource 嵌套 Repeater?

转载 作者:数据小太阳 更新时间:2023-10-29 02:19:51 25 4
gpt4 key购买 nike

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

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

我会在下面的代码中为子 Repeater 的 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>

最佳答案

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

<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 代码。

The secret sauce is the XPathSelect apparently .

关于.net - 如何使用单个 XMLDataSource 嵌套 Repeater?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5875682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com