I need an example of linq to xml query.
I have two ListBoxes with SelectionMode set to Multiple.
My query for populating first ListBox is:
var query = doc.Root.Descendants("Articles")
.OrderBy(b => b.Element("Category").Value)
.Select(b => b.Element("Category").Value)
.Distinct();
and binding it with:
lbxItems.DataSource = query;
lbxItems.DataBind();
So i have all the values in first ListBox, and when i select item from that ListBox i want to populate second ListBox.
So on SelectedIndexChanged i have another query:
var query = doc.Root.Descendants("Articles")
.Where(b => b.Element("Category").Value.Equals(lbxItems.SelectedValue))
.OrderBy(b => b.Element("SubCategory").Value)
.Select(b => b.Element("SubCategory").Value)
.Distinct();
That’s working if i select one item, but i need a query that is doing the same thing but from multiple selected items.
Thank you.
Try changing your where clause like so:
The idea is to determine what items are selected and see if your category value is among those selected.