If you find this article useful, consider making a small donation to show your support for this web site and its content.
DiscountASP
AboutMe
About me:
Hi. My name is Farooq Kaiser and I'm a software developer from Toronto, Canada.

Populating drop down list with XML in C#

by Farooq Kaiser 26. January 2009 06:54
 Today, i will show you how to populate drop down list with xml data.
 Let's say we have the following xml.
 
 <users>
 <user>
<id>001</id> 
<name>James</name> 
</user> 
<user>
<id>002</id> 
<name>Paul</name> 
</user>  
</users> 

 
XmlDocument doc = new XmlDocument();
                doc.Load(@"Users.xml");

                XmlNodeList xnl = doc.SelectNodes("users/user");

                foreach (XmlNode node in xnl)
                {
                    drpUser.Items.Add(new ListItem(node.FirstChild.InnerText, node.LastChild.InnerText));
                }
 
     Let me know if you have any questions. 

Currently rated 2.5 by 2 people

  • Currently 2.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

.NET | C# | XML

Comments

Jobs Autos Real estate Videos Power by Google
awesome comments