Populating DropDownList using Xml File

You can easily populate a DropDownList with the data from the xml file. Check out the code below:

XML File

 


	
    hank 
    
    
    corry
    
    
    david
     
    
    james
    
 

C# CODE

 
XmlDocument doc = new XmlDocument();
				doc.Load(Server.MapPath("Menu.xml"));
				XmlNodeList nodeList = doc.SelectNodes("names/name");

				foreach(XmlNode node in nodeList)
					DropDownList1.Items.Add(new ListItem(node.SelectSingleNode("client").InnerText));
			

Print | posted @ Thursday, August 18, 2005 1:31 PM

Twitter