Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Bind XML to Drodownlist

Posted on 2006-10-20
9
Medium Priority
?
487 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

688 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