# How To Fill Dropdownlist With XML in ASP.NET

In this article we will see that how we can populate a DropDownList control with XML file as a source.Our XML file looks something like below which simply contains the name of the clients.
<?xml version="1.0" encoding="utf-8" ?>
<names>
<name>
<client>hank</client>
</name>
<name>
<client>corry</client>
</name>
<name>
<client>david</client>
</name>
<name>
<client>james</client>
</name>
</names>
Filling a DropDownList with XML file: Now we want to fill the DropDownList with the contents contained in the XML file. Don't forget to include the namespace System.XML.
private void FillDropDownList()
{
XmlDocument doc = new XmlDocument();
XmlNodeList nodeList = doc.SelectNodes("names/name");
foreach (XmlNode node in nodeList)
}
All we are doing is making an object of the XmlDocument class. Than we read the XML file, dig down in the nodes and selects the nodes that we want. And finally add those node's inner text to the DropDownList items.
Reactions

1. It's really helpful topic and has solved my doubt

Emoji
(y)
:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
x-)
(k)