Solved

Bind XML to Drodownlist

Posted on 2006-10-20
9
484 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Where is this file? 3 42
Consume a webservice via VB in Visual Studio 2015 3 45
Calculating percentage 2 49
How to fix 'event logs could not be searched' error asp.net? 3 26
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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