重复项目将 XML 加载到复选框列表 (vb.net)
您好,我正在尝试加载 XML 文档并填充一些复选框列表。我使用 DataTextField 如下。
<asp:CheckBoxList ID="cblcountry" runat="server" DataTextField="CountryofBirth">
在后面的代码中我使用下面的代码。
Dim dSet As New DataSet
dSet.ReadXml(Server.MapPath("xsource.xml"))
cblcountry.DataSource = dSet
cblcountry.DataBind()
这是 xml 文档。
<pupil>
<academicYear>2011/2010</academicYear>
<grade>Kindergarten 1</grade>
<class>class 1</class>
<name>emma</name>
<admissionDate>01/05/2010</admissionDate>
<CountryofBirth>United Kingdom</CountryofBirth>
<fullName>emma watson</fullName>
</pupil>
它加载一切都很好。但它有重复的项目。例如,如果有 5 个人的出生国家/地区是英国,则复选框列表会显示 5 次。如果我从 1 个 XML 块中删除 CountryofBirth,它仍然显示一个空白复选框项。
所以我的问题是如何获取复选框列表而不显示那些重复的数据。我正在开发一个原型(工作演示),因此最简单的方法将更受赞赏。
非常感谢你们。我喜欢这个论坛。
Hi i am trying to load XML document and populate few checkboxlist. I use DataTextField as below.
<asp:CheckBoxList ID="cblcountry" runat="server" DataTextField="CountryofBirth">
And in the code behind i use this code below.
Dim dSet As New DataSet
dSet.ReadXml(Server.MapPath("xsource.xml"))
cblcountry.DataSource = dSet
cblcountry.DataBind()
And this is xml doc.
<pupil>
<academicYear>2011/2010</academicYear>
<grade>Kindergarten 1</grade>
<class>class 1</class>
<name>emma</name>
<admissionDate>01/05/2010</admissionDate>
<CountryofBirth>United Kingdom</CountryofBirth>
<fullName>emma watson</fullName>
</pupil>
It loads everything fine. But it has duplicated items. For example, if there are 5 people with CountryofBirth is United Kingdom than checkboxlist show it 5 times. If i delete CountryofBirth from 1 block of XML, it still shows a blank checkboxitem.
So my question is how do i get checkboxlist without showing those duplicated data. I am just developing a prototype (working demo) so easiest way would be more appreciated.
Thanks so much guys. I love this forum.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下拉列表将为 XML 文档中的每个 Pupil 元素添加一个列表项。您应该首先将 XML(或数据集)过滤到不同的国家/地区列表,然后绑定到下拉列表控件。
使用 Linq 示例进行编辑:
首先,从 Aspx 页面中删除 DataTextField="CountryofBirth"。
第二...
The drop down list will add a list item for every Puplil element in the XML document. You should first filter the XML (or dataset) to a distinct list of countries and then bind to the drop down list control.
Edit w/ Linq Example:
First, remove the DataTextField="CountryofBirth" from your Aspx Page.
Second...