Why is my control not populated with XML data?

M

mark4asp

I have created two DropDownList controls on my form which I want to
populate with data from an XML file (stored in the xml subdirectory)

Here is the code I use.

It does not work. I shows "System.Data.DataRowView" in both the value
and text fields of the DropDownLists

In debug, I noticed that:
ds.Tables["date"].Rows.Count = 20
dds.Tables["date"].DefaultView.Count = 20

There are 20 items in the xml file.

Furthermore, when I add a watch for "ds.Tables["date"].DefaultView", I
can click on "Data View Visuliser" (in debug again) and it shows the
table information (20 rows, 2 columns each).

What else do I need to do to load this xml data into my controls?

1) code:

DataSet ds = new DataSet();
ds.ReadXml(@"..\xml\dates.xml");

ddlFromDate.DataSource = ds.Tables["date"].DefaultView;
ddlFromDate.DataBind();
ddlToDate.DataSource = ds.Tables["date"].DefaultView;
ddlToDate.DataBind();

2) xml file: dates.xml

<?xml version="1.0"?>
<dates>
<date>
<dateValue>20021</dateValue>
<dateText>2002 1st Qtr</dateText>
</date>
<date>
<dateValue>20022</dateValue>
<dateText>2002 2nd Qtr</dateText>
</date>
<date>
<dateValue>20023</dateValue>
<dateText>2002 3rd Qtr</dateText>
</date>
<date>
<dateValue>20024</dateValue>
<dateText>2002 4th Qtr</dateText>
</date>
<date>
<dateValue>20031</dateValue>
<dateText>2003 1st Qtr</dateText>
</date>
<date>
<dateValue>20032</dateValue>
<dateText>2003 2nd Qtr</dateText>
</date>
<date>
<dateValue>20033</dateValue>
<dateText>2003 3rd Qtr</dateText>
</date>
<date>
<dateValue>20034</dateValue>
<dateText>2003 4th Qtr</dateText>
</date>
<date>
<dateValue>20041</dateValue>
<dateText>2004 1st Qtr</dateText>
</date>
<date>
<dateValue>20042</dateValue>
<dateText>2004 2nd Qtr</dateText>
</date>
<date>
<dateValue>20043</dateValue>
<dateText>2004 3rd Qtr</dateText>
</date>
<date>
<dateValue>20044</dateValue>
<dateText>2004 4th Qtr</dateText>
</date>
<date>
<dateValue>20051</dateValue>
<dateText>2005 1st Qtr</dateText>
</date>
<date>
<dateValue>20052</dateValue>
<dateText>2005 2nd Qtr</dateText>
</date>
<date>
<dateValue>20053</dateValue>
<dateText>2005 3rd Qtr</dateText>
</date>
<date>
<dateValue>20054</dateValue>
<dateText>2005 4th Qtr</dateText>
</date>
<date>
<dateValue>20061</dateValue>
<dateText>2006 1st Qtr</dateText>
</date>
<date>
<dateValue>20062</dateValue>
<dateText>2006 2nd Qtr</dateText>
</date>
<date>
<dateValue>20063</dateValue>
<dateText>2006 3rd Qtr</dateText>
</date>
<date>
<dateValue>20064</dateValue>
<dateText>2006 4th Qtr</dateText>
</date>
</dates>

3) xsd file: dates.xsd

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="dates">
<xs:complexType>
<xs:sequence>
<xs:element name="date">
<xs:complexType>
<xs:sequence>
<xs:element name="dateItem" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="dateCode" type="xs:integer"/>
<xs:element name="dateText" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top