Frage

I've been struggling on a way to do this for a while. I have this a listbox in asp.net that I use that looks like :

<asp:ListBox ID="lstLinkedProspect" runat="server" SelectionMode="Multiple" />

What I want to do with it is to be able to select all items I have in a specific table, all except the one that are in the listbox. Not only the selected but all items that are already in the list. I use System.Linq.Dynamic library. Here is what I'm trying to do :

Dim lstProspect = dbConnection.Prospects.Where(If(String.IsNullOrWhiteSpace(SearchFilters.Value), "ProspectId > 0", SearchFilters.Value).ToString) _
                                                .Except(' There goes all the items in the list box)

What I have already tried is :

Dim lstProspect = dbConnection.Prospects.Where(If(String.IsNullOrWhiteSpace(SearchFilters.Value), "ProspectId > 0", SearchFilters.Value).ToString) _
                                                .Except(lstLinkedProspect.Items.Cast(Of ListItem)().Where(Function(x) x.Value).Cast(Of Beans.Prospect))

Is it possible in Linq to get all the items from a table that are not in the listbox? Note that the Value property of the ListItem in the listbox is the ProspectId.

Thanks in advance.

War es hilfreich?

Lösung

This is the the code I found to achieve what I was looking for :

Dim lstItems = dbConnection.Prospects.Where(Function(x) ids.Contains(x.ProspectId))
Dim lstProspect = dbConnection.Prospects.Where(If(String.IsNullOrWhiteSpace(SearchFilters.Value),
"ProspectId > 0", SearchFilters.Value).ToString).Except(lstItems)

Hope this can help anyone struggling with that problem.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top