Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 如何使用单个XMLDataSource使用嵌套中继器?_.net_Xml_Repeater_Xmldatasource - Fatal编程技术网

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

.net 如何使用单个XMLDataSource使用嵌套中继器?,.net,xml,repeater,xmldatasource,.net,Xml,Repeater,Xmldatasource,我希望使用嵌套的中继器,它们共享相同的XML数据源,父中继器将数据源传递给子中继器,这样就不需要为父中继器中的每个数据项重新访问数据源 父中继器的XPATH:“/adpdelection/Documents/Document[@type='A']/Funds/Fund[@cuspid='1234']” 在下面的代码中,我应该为子转发器中的DataSource属性设置什么 我不想使用OnItemDataBound,因为我认为它不需要,但我想我可能错了 <asp:XmlDataSour

我希望使用嵌套的中继器,它们共享相同的XML数据源,父中继器将数据源传递给子中继器,这样就不需要为父中继器中的每个数据项重新访问数据源

父中继器的XPATH:“/adpdelection/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>

第一基金
二号基金
第三基金
第四基金

经过更深入的挖掘,我终于找到了答案。以下是工作代码:

<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。。。在当前设置中。。。但是如果您使用for/foreach循环,则不会。。。这就完全取消了中继器的使用。。。但是你需要小心地将数据排列在代码背后的列表/Arryas中…@sani-谢谢。然而,我看到它是这样做的。我只是不确定他们是如何想到DataSource属性中的内容的,因为我看到的示例没有显示XML,所以我看不到ASP.NET代码背后的逻辑。我只想明确一点:使用Repeater和OnItemDataBound比使用自己的for/foreach处理更好。中继器的性能会受到影响(我被告知),但除非您有一个非常繁忙的站点,否则中继器就足够了……对于您应该放在childs数据源项中的内容,它应该是反映ReplacementFunds列表/数组的parents数据类型属性。@sani-谢谢;你能把它作为一个答案,这样我就可以接受它来给你评分吗?你说没有
OnItemDataBound
,但是在你的代码中有
OnItemDataBound=“rptCurrentFund\u ItemDataBound”
-那么哪一部分是正确的?我不记得了-可能只是被注释掉了/空函数,当我试图弄清楚这一切时,它就在那里。