hi i have a question to linq to xml ...
i have a xml file with Title value:
my xml:
<?xml version="1.0" encoding="utf-8"?>
<Titles>
<values id="de">
<value value="Herr" display="Herr"></value>
<value value="Frau" display="Frau"></value>
</values>
<values id="cs">
<value value="Herr" display="Pan"></value>
<value value="Frau" display="Paní"></value>
</values>
<values id="en">
<value value="Herr" display="Mr."></value>
<value value="Frau" display="Mrs."></value>
</values>
<values id="es">
<value value="Herr" display="Sr."></value>
<value value="Frau" display="Sra."></value>
</values>
<values id="zh">
<value value="Herr" display="先生"></value>
<value value="Frau" display="女士"></value>
</values>
</Titles>
and I have a DropDownList:
<td><asp:DropDownList ID="drp_GuestListViewAddDialog_GuestTitle" runat="server"></asp:DropDownList></td>
here is my c# code:
XDocument x = XDocument.Load(Server.MapPath(@"~\App_Data\DropDown\Title.xml"));
string data = (from item in x.Elements("Titles").Elements("values") where item.Attribute("id").Value == "de" select item.Attribute("display").Value).First();
UPDATE:
For Example if I want the id = "de" I want this
<values id="de">
<value value="Herr" display="Herr"></value>
<value value="Frau" display="Frau"></value>
</values>
valueand thetextyou want in your dropdownlist? You need anIEnumerableto be your datasource, but you are selecting a single string.