<?xml version="1.0" encoding="utf-8" ?> <dropdowns> <dropdown name="DropDownLoc"> <menu text="Select" value="-1" /> <menu text="North" value="1200" /> <menu text="South" value="1400" /> </dropdown> <dropdown name="DropDownEsp"> <menu text="Select" value="-1" /> <menu text="Est" value="7" /> <menu text="Ovest" value="9" /> </dropdown> </dropdowns>
<asp:DropDownList ID="DropDownList1" runat="server"> </asp:DropDownList> <asp:XmlDataSource ID="XmlDataSource1" runat="server" datafile=& </asp:XmlDataSource>
string path = Server.MapPath("~/XMLFile3.xml"); string whichDropDown = "DropDownEsp"; var query = from dropDown in XDocument.Load(path).Descendants("dropdown") where dropDown.Attribute("name").Value == whichDropDown from name in dropDown.Descendants("name") let text = name.Attribute("text").value let value = name.Attribute("value").value select new ListItem(text, value); // Now we data bind the query result to the control DropDownList1.DataSource = query; DropDownList1.DataBind();
DropDownList1.DataValueField = "value"; DropDownList1.DataTextField = "text"; DropDownList1.DataSource = query; DropDownList1.DataBind();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)