我有以下 XML:
<questions>
<question text="This is a test question?">
<answer value="Yes">
<requirement articleId="2899"/>
</answer>
<answer value="No">
<requirement articleId="2899"/>
</answer>
</question>
</questions>
我的 ASPX 页面中有以下标记:
<asp:Repeater ID="rptQuestions" runat="server" DataSourceID="xdsQuestions">
<ItemTemplate>
<p>
<asp:Label ID="lblText" runat="server" Text='<%# Eval("text") %>' />
</p>
<div>
<asp:RadioButtonList ID="rblAnswers" runat="server" RepeatDirection="Horizontal"
RepeatLayout="Flow" AutoPostBack="true" OnSelectedIndexChanged="rblAnswers_SelectedIndexChanged"
DataSource='<%# XPathSelect("answer") %>' DataTextField="value" DataValueField="value" />
</div>
</ItemTemplate>
</asp:Repeater>
<asp:XmlDataSource ID="xdsQuestions" runat="server" DataFile="~/App_Data/QA.xml"
XPath="./questions/question" />
到目前为止,我能够让它工作的唯一方法是将“answer”节点的“value”属性移动到元素中(如下所示<value>Yes</value>
:)并绑定到“answer”的“InnerText”属性节点,因为 XPathSelect 返回 XmlElement 的集合。这不是我想要的,因为如果“answer”的任何其他子节点(例如“requirement”节点)也有 InnerText,它会与 RadioButtonList 的 ListItems 中的“value”一起连接.
关于如何在不更改 XML 的情况下绑定我的 RadioButtonList 的任何建议?