MVC
Web forms
Web forms Tutorials

MultiLookup Tutorial


Previous Tutorial
In order to proceed please first download the Finished solution from the Previous Tutorial, or use yours if you've done it.

1. Add these methods in Aja.svc.cs
    [WebGet]
    [OperationContract]
    public IEnumerable<KeyContent> FruitGetMultiple(string v)
    {
        var ids = v.GetIntArray();
        return Fruits.Where(o => ids.Contains(o.Id)).Select(f => new KeyContent(f.Id, f.Name));
    }

    [WebGet]
    [OperationContract]// this could be used for the Lookup as well (selected would always be null and sel would be empty array)
    public LookupResult FruitSearchMultiLookup(string search, string selected, int page)
    {
        var sel = selected.GetIntArray();

        var items = Fruits.Where(o => o.Name.ToLower().Contains(search.ToLower()) && !sel.Contains(o.Id))
            .Select(f => new KeyContent { Key = f.Id, Content = f.Name });

        const int pageSize = 5;
        return new LookupResult
        {
            Items = items.Skip((page - 1) * pageSize).Take(pageSize),
            More = items.Count() > page * pageSize
        };
    }

    [WebGet]
    [OperationContract]
    public IEnumerable<KeyContent> FruitSelected(string selected)
    {
        var sel = selected.GetIntArray();
        return Fruits.Where(o => sel.Contains(o.Id))
            .Select(f => new KeyContent { Key = f.Id.ToString(), Content = f.Name });
    }

2. In default.aspx add this line:
    <o:MultiLookup runat="server" GetMultipleUrl="~/Aja.svc/FruitGetMultiple" SearchUrl="~/Aja.svc/FruitSearchMultiLookup" SelectedUrl="~/Aja.svc/FruitSelected" />

3. Run it (Ctrl + F5)