Click here to Skip to main content
15,914,642 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an xml file
XML
<product>
<idproduct>1</idproduct>
<name>milk</name>
<unit>can</ unit>
<cost>$2</cost>
</product>
<product>
<idproduct>2</idproduct>
<name>oranges</name>
<unit>barrel</unit>
<cost>$10</cost>
</product>

...
how to load unit from the xml to Dropdownlist?
I tried using Items.Add (node ​​[2]. InnerText) and SelectedIndexChanged like winform C #.I get number of Item increase.Unit repeat in Dropdownlist.
Posted
Updated 30-Dec-11 18:55pm
v2

Hi,

Try this below sample:

C#
private void button2_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            XmlTextReader r = new XmlTextReader(@"XML File Path");
            r.Read();

            while (r.Read())
            {
                if (r.NodeType == XmlNodeType.Element)
                {
                    if (r.Name == "unit")
                    {
                        r.Read();
                        listbox1.Items.Add(Convert.ToString(r.Value));
                    }
                }
            }
        }


Regards,
Vasuki.
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900