Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding XML values to dropdownlist, c#
    primarykey
    data
    text
    <p>I've been messing around with the following code to add each node in an xml fileto a dropdown list but with incorrect results so far.</p> <pre><code> XmlDocument XmlDoc = new XmlDocument(); XmlDoc.Load(Server.MapPath("~/Upload/" + FileUpload1.FileName)); XmlNodeList question = XmlDoc.GetElementsByTagName("row"); foreach(XmlNode Node in question) { string answer = Node["var"].Attributes["name"].InnerText; string ques = Node["var"].InnerText; DropDownList1.Items.Add(new ListItem(answer, ques)); } </code></pre> <p>Here is my xml file</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" standalone="yes"?&gt; &lt;root&gt; &lt;row&gt; &lt;var name="Name" value="Garcia" /&gt; &lt;var name=" Surname" value=" Jose" /&gt; &lt;var name=" Country" value=" Cuba" /&gt; &lt;var name=" Job" value="Software Developer" /&gt; &lt;var name=" Cabin" value="345A" /&gt; &lt;/row&gt; &lt;row&gt; &lt;var name="Name" value="Lenon" /&gt; &lt;var name=" Surname" value="Tim" /&gt; &lt;var name=" Country" value="USA" /&gt; &lt;var name=" Job" value="SoftwareDeveloper" /&gt; &lt;var name=" Cabin" value="444" /&gt; &lt;/row&gt; &lt;row&gt; &lt;var name="Name" value="Rusell" /&gt; &lt;var name=" Surname" value=" Anthony" /&gt; &lt;var name=" Country" value=" UK" /&gt; &lt;var name=" Job" value="Web Designer" /&gt; &lt;var name=" Cabin" value="345" /&gt; &lt;/row&gt; &lt;row&gt; &lt;var name="Name" value="Wolf" /&gt; &lt;var name=" Surname" value=" Werner" /&gt; &lt;var name=" Country" value=" Germany" /&gt; &lt;var name=" Job" value="Linux IT" /&gt; &lt;var name=" Cabin" value="234 " /&gt; &lt;/row&gt; &lt;/root&gt; </code></pre> <p>What I need to do is just populate a drop down list with the values Name,Surname,Country,Job and Cabin,so the user can select these values to manipulate the data. I realise with the answer tag im accessing the values also I was trying different things from code ive saw.</p> <p>The results im getting in my dropdown list from this code is Name Name Name Name Im adding the first attribute of each node, but what I need to do is add every value from just one node. NOTE: The xml files il be working with will have different values and names etc so hardcoding is not an option.</p> <p>If anyone could help Id appreciate it, thank you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload