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.
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…