Basically what you need to do is transform the list data you have retrieved from the database into a List<SelectListItem>
so it can be displayed. The Linq
Select
method makes this pretty easy:
objListboxViewModel.resourcename =
listboxdata.Select(x => new SelectListItem() { Text = x.DisplayName,
Value = x.ID.ToString() })
.ToList();
So what you set the Text
and Value
properties to will depend on what the definition of GetResourceOrderDisplay_Result
looks like and what properties it has. In the Select
method the x
represents a single element of the listboxdata
list and is of type GetResourceOrderDisplay_Result
, so you can access it's properties like x.Property
. The Select
method constructed in this way will return a new list of SelectListItem
.