Click here to Skip to main content
15,614,138 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

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

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

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.
Updated 2-Apr-15 0:18am
Sinisa Hajnal 2-Apr-15 6:18am    
Why not search before you ask?

1 solution

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