如何使用单个 XMLDataSource 来使用嵌套中继器?
我想使用共享相同 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过更广泛的挖掘后,我实际上找到了答案。这是工作代码:
这就像一个魅力,不需要 OnItemDataBound 代码。
秘密武器显然是 XPathSelect。
I actually found my answer after some more extensive digging. Here's the working code:
This works like a charm with no OnItemDataBound code required.
The secret sauce is the XPathSelect apparently.