Tech Off Post

Single Post Permalink

View Thread: How to populate text box with the xml's attribute's value based on the combobox's selection
  • User profile image

    I have a xml file with the  fields country name, pin, state, currency. The Sample xml is shown below

    <Country Name="India" State = "TN" Currency ="RS" PIN = "123456" />
    <Country Name = "USA" State = "TX" Currency ="$" PIN= "123456" />

    So I had shown the country names as a combo box, and it's values are populated by using the following code

    using System.Xml;
    using System.IO;
    private void showCountryDetails()
    string filename = "countryDetails.xml";
    var path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
    path += @"\" + fileName;
    XmlDocument countryDetailsXmlDoc= new XmlDocument();
    XmlNodeList listCountryDetails = countryDetailsXmlDoc.SelectNodes("/Countries/Country");
    foreach (XmlNode node in listCountryDetails)

    Now all the names of the countries are populated in the combo box, assume that I am choosing India in the combo box, and I want populate all the attributes from the xml in to the text box,for example the state's value should be displayed in the state text box and the Currency value should be displayed in the Currency text box and so on.

    Could someone please help me out here ?


    Varun Krishna. P