Hi I have a MultiSelectList that I want to split into several smaller MultiSelectList, depending on the value (NOT the selectedValues), and I want to use LINQ to achieve that...sure it is possible but I can't cut it..any suggestions? Thanks.
Asked
Active
Viewed 299 times
3 Answers
0
is this what you want:
var multiSelectList= new MultiSelectList(new List<string>()); //your mutli-select list
var multiSelectListGroupedByValue=ms.GroupBy(x => x.Value)
.Select(x=>new MultiSelectList(x.Select(y=>y.Value)));

Baz1nga
- 15,485
- 3
- 35
- 61
0
Use this code (get it from here Split a collection into `n` parts with LINQ?)
static class LinqExtensions
{
public static IEnumerable<IEnumerable<T>> Split<T>(this IEnumerable<T> list, int parts)
{
int i = 0;
var splits = from item in list
group item by i++ % parts into part
select part.AsEnumerable();
return splits;
}
}
0
I hope this is what you need
@{
var array = new int[] { 1,2,3,4,5,6,7,8,9,10 };
}
@Html.ListBox("lstBoxLessThan5",new MultiSelectList(array.Where(a => a < 5).ToArray()));
<br />
@Html.ListBox("lstBoxMorethan5",new MultiSelectList(array.Where(a => a > 5).ToArray()));
Put whatever business logic inplace of temp datastructure 'array'

Pravin Pawar
- 2,559
- 3
- 34
- 40