I want to display values in a DDL using a XML file and i am using LINQ to XML
<countrys>
<country>
<name>India</name>
<state>
<text>Maharashtra</text>
<text>Kashmir</text>
<text>Goa</text>
</state>
</country>
<country>
<name>Sri lanka</name>
<state>
<text>Kanady</text>
<text>Colombo</text>
<text>Galle</text>
</state>
</country>
<country>
<name> Australia</name>
<state>
<text>Sydney</text>
<text>Perth</text>
<text>Melbourne</text>
</state>
</country>
<country>
<name>South Africa</name>
<state>
<text>Capetown</text>
<text>Johanusburg</text>
<text>Durban</text>
</state>
</country>
</countrys>
public static IEnumerable bindstate()
{
var state = from b in getdata().Descendants(("state"))
orderby (string) b.Element("text")
select (string) b.Element("text");
return state;
}
but i am not getting all the states i am getting only first state in every country how can i get all the states?
You can use
SelectManyfor this:In this example,
SelectManyselects the"text"elements from each"state"element and flattens them into one sequence.