Click here to Skip to main content
15,886,781 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a drop downlist with xml files. when i select 1 from there i need to populate another dropdown list with just the nodes..

my c# code that populates the 1st dropdown with the xml files

C#
protected void Page_Load(object sender, EventArgs e)
    {

        DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath("/Xmlscripts"));
        lblFolderLocation.Text = dirInfo.ToString(); // displays the folder location in a lable
        FileInfo[] fileList = dirInfo.GetFiles();
        foreach (FileInfo fileInfo in fileList)
        {
            dropdownlist1.Items.Add(new ListItem(fileInfo.Name, fileInfo.Name));
        }
}


I need help populating the second dropdown list with the nodes of the xml file when selected

Example of xml file below

XML
<Script>
  <greeting> // need to display in second drop box
    <data>hi how you</data>
  </greeting>
  <verification> // need to display in second drop box
     <data> can i confirm it is Mike</data>
  </verification>
  <dropOf> // need to display in second drop box
    <data>when can i drop off?</data>
  </dropOf>
  <infoRequired> // need to display in second drop box
     <data>need the proof of payment</data>
  </infoRequired>
  <example> // need to display in second drop box
    <data> till slip</data>
  </example>
  <end> // need to display in second drop box
     <data>Thank you</data>
  </end>
</Script>


I want to add just the greeting, verification, dropOf, infoRequired, example, and end to the second dropdown list so when i click on one of them it will be able to display in a textbox.
Posted
Updated 2-Apr-15 0:18am
v2
Comments
Sinisa Hajnal 2-Apr-15 6:18am    
Why not search before you ask?
https://social.msdn.microsoft.com/Forums/en-US/f4db0e0a-5a99-4757-95f8-6995edaa8885/popoulate-xml-data-in-combo-box?forum=csharplanguage

1 solution

CSS
XMLDocument and XMLNode class can be used for a more granular logic of finding nodes. In your case I feel, Linq to XML can be used to query a XML string and bind relevant nodes with dropdown.

Would suggest you look at this reference links

https://msdn.microsoft.com/en-us/library/bb943906.aspx
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900