Radiobuttonlist内部的中继器绑定到xmldataSource
-
10-12-2019 - |
题
我有以下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" />
.
到目前为止,我能够实现这一点的唯一方法是将“答案”节点的“值”属性移动到元素(如下:<value>Yes</value>
)中,并绑定到“Innertext”属性“答案”节点,因为XPathSelect返回XMLElement的集合。这不是我想去的方式,因为如果'答案'的任何另一个子节点(例如'要求'节点)也有Innertext,它会在RadiobuttonList的listItem中连接到“值”。
关于如何绑定我的radiobuttonlist而不改变XML的任何建议?
解决方案
在RadiobuttonList中,将数据源更改为以下内容:
DataSource='<%# XPathSelect("answer/@value") %>'
不隶属于 StackOverflow