Solved

Bind XML to Drodownlist

Posted on 2006-10-20
9
480 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

11 Experts available now in Live!

Get 1:1 Help Now