Fill Combo Box from the XMLThis is very common article .We always come into situations in which we need to fetch values from xml and fill the combo box.In this article, I will show you how to fill the combo box by fetching the data from xml.
This is the below sample XML:
<Details>
<RequestTypeDetails>
<RequestType>
<value>News</value>
</RequestType>
<RequestType>
<value>Press Release</value>
</RequestType>
<RequestType>
<value>Content Update</value>
</RequestType>
</RequestTypeDetails>
</Details>
Now the c# code to fetch and bind the data with combo box:
private void Form1_Load(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
//Path of the XMl file
doc.Load("D:\\SharePointCOM\\RequestForm\\RequestForm\\XMLRequestType.xml");
// Read the node of the XML
XmlNodeList RequestTypeNodes = doc.GetElementsByTagName("RequestTypeDetails");
// Make a object of list type
List RequestTypeMails = new List();
// Read the XML child node and fill the List
foreach (XmlNode node in RequestTypeNodes[0].ChildNodes)
{
RequestTypeMails.Add(node.InnerText);
}
// Bind the data of the list to the combo box(cmbRequestType)
cmbRequestType.Items.AddRange(RequestTypeMails.ToArray());
}
And the output of this code will be like this:
Thanks!!!!!!