Solved

Bind XML to Drodownlist

Posted on 2006-10-20
9
479 Views
Last Modified: 2008-01-09
HI,
 I have an XML File Like this
<Category>
  <note Title="p501">
    <param1>Tove</param1>
    <param2>Jani</param2>
    <param3>Reminder</param3>
  </note>

  <note Title="p502">
    <param1>Jani</param1>
    <param2>Tove</param2>
    <param3>Re: Reminder</param3>
  </note>
</Category>

How Do I Bind The "Title" in the XML file at a dropdown list.
Also I need a good way to get the params of a selected title in the drodownlist

I am using ASP.NET 2005 (C#)
Thanks
0
Comment
Question by:madmare
  • 5
  • 2
  • 2
9 Comments
 
LVL 12

Expert Comment

by:Pra4444
ID: 17776473
This should do the trick for you..
http://www.w3schools.com/aspnet/aspnet_xml.asp

it should also work for a dropdownlist.....

as for the second part,you can write it in the dropdownlist selected index change event...

XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("Menu.xml"));
XmlNodeList nodeList = doc.SelectNodes(dropdownlist.selectednodevalue);
foreach(XmlNode node in nodeList)
 DropDownList.Items.Add(new ListItem(node.SelectSingleNode("param1").InnerText));
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17776760
Dim doc as New XmlDOcument();
doc.Load(Server.MapPath("yourfile.xml"));

DropDownList1.DataSource = doc.SelectNodes("/Category/note[@Title]");
DropDownList1.DataBind();
0
 

Author Comment

by:madmare
ID: 17776795
C# please
0
 
LVL 12

Expert Comment

by:Pra4444
ID: 17776897
apart from the first line all the other lines are in C#...

XmlDocument doc = new XmlDocument();
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 35

Expert Comment

by:YZlat
ID: 17776919
sorry about that - should be

XmlDOcument doc=New XmlDocument();
doc.Load(Server.MapPath("yourfile.xml"));

DropDownList1.DataSource = doc.SelectNodes("/Category/note[@Title]");
DropDownList1.DataBind();



0
 

Author Comment

by:madmare
ID: 17776938
my question was how do I get the value of param1 for the selected "Title" at the Dropdownlist
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17777068
doc.SelectSingleNode("/Category/note[@Title='" + DropDownList1.SelectedValue + "']");
0
 
LVL 35

Accepted Solution

by:
YZlat earned 500 total points
ID: 17777091
XmlNode xnode=doc.SelectSingleNode("/Category/note[@Title='" + DropDownList1.SelectedValue + "']/param1");

String param1=xnode.InnerText
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17777129
oops, forgot the semicolon after InnerText
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now