内部中继RadioButtonList的必然的XmlDataSource [英] RadioButtonList inside Repeater bound to XmlDataSource

查看:173
本文介绍了内部中继RadioButtonList的必然的XmlDataSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的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页面:

And I have the following markup in my ASPX page:

<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" />

到目前为止,我已经能够得到这个工作的唯一办法是答案节点的价值属性转移到元素(像这样:&LT;价值&GT;是&LT ; /值&GT; ),并绑定到'答案'节点'的InnerText属性,因为XPathSelect正在返回的XmlElement的集合。这不是我要如何去了解它,因为如果任何'答案'的其他子节点(如规定节点),还拥有的InnerText,它就会与价值的单选按钮列表的ListItems的串联一起

So far the only way I've been able to get this to work is to move the 'value' attribute of the 'answer' node into the element (like this: <value>Yes</value>) and bind to the 'InnerText' property of the 'answer' node, since XPathSelect is returning a collection of XmlElement. This is not how I want to go about it, because if any of the other child nodes of 'answer' (such as the 'requirement' node) also has InnerText, it gets concatenated along with 'value' in the ListItems of the RadioButtonList.

如何到我的单选按钮列表绑定在不改变XML有什么建议?

Any suggestions on how to bind my RadioButtonList without changing the XML?

推荐答案

在你的单选按钮列表,您的数据源更改为以下内容:

Inside your RadioButtonList, change your DataSource to the following:

数据源='&LT;%#XPathSelect(接听/ @值)%GT;

这篇关于内部中继RadioButtonList的必然的XmlDataSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆