User Id :    Password :      New Member   Forgot Password  
 
Fill Combo Box from the XML
Description Fill Combo Box by fetching the data from XML.   No. of Views     4744
  Rating     0
Author Gaurav   Posted On     02 Sep 2012
Tags Windows Programming,XML,XML : General    

Sample Code   Download Code

This 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!!!!!!

About Author

About Author I am as simple as c#. Gaurav
No Photo
 
Country India
Company N/A
Home Page N/A

Rate this article

Rating options from poor, fair, good, very good to excelent.  
 

Comments

   
Write your comment here.
Comment
Verification Code