MVC
Web forms
Web forms Tutorials

MultiLookup

The MultiLookup is similar to the Lookup except it requires 3 urls, one additional url is for showing the selected items in the popup, and the url used for showing the value in the readonly field receives a json array of the selected items and must return a collection of string. Also the SearchUrl will receive a selected parameter - array of the selected items.

The MultiLookup requires 3 urls to service methods:

so here's an example:

    <o:MultiLookup runat="server" ID="Fruits" GetMultipleUrl="~/svc/aja.svc/FruitGetMultiple"
 SearchUrl='~/svc/aja.svc/FruitSearch' SelectedUrl="~/svc/aja.svc/FruitSelected" ClearButton="true" />
    
[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]
public LookupResult FruitSearch(string search, string selected, int page)
{
    var sel = selected.GetIntArray();

    var items = Fruits.Where(o => o.Name.Contains(search) && !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 });
}
    

The GetIntArray method is an extension shown here

Binding to parents, parameters

The MultiLookup can be bound to one or multiple parents, and parameters with values can be sent, all exactly like the AjaxDropdown
Additional parameters (parents, predefined values) will be sent to all 3 urls.

Setting or getting the Value

there are 2 properties for this:

example:

int[] vals = new int[] {1, 2, 3, 4, 5};
            
Fruits.Value = vals.ToJson(); //extension from Omu.AwesomeWebForms

int[] arr2 = Fruits.Value.GetIntArray(); // extension from Omu.AwesomeWebForms
  

Misc properties

ClearButton if true will add a "x" button used to clear the value of Lookup
PopupWidth the width in px of the popup window
PopupHeight the height in px of the popup window
FullScreen if true the lookup window will take all the available width and height
Modal Modal Popup true/false