Skip to content

DevExpress-Examples/asp-net-mvc-combobox-bind-to-large-filtered-data-source

Repository files navigation

Combo Box for ASP.NET MVC - How to filter a large data source and automatically select the first item

This example demonstrates how to use the combo box editor's BindList method to bind the editor to a large filtered data source.

Bind a combo box editor to a large data source

Overview

Use the editor's BindList method and pass the following methods as parameters:

var comboBox = Html.DevExpress().ComboBox(settings => {
    settings.Name = "comboBox";
    <!-- ... -->
}).BindList(ComboBoxLargeDataBase.Model.DataHelper.GetPersonsRange, ComboBoxLargeDataBase.Model.DataHelper.GetPersonByID);
public static object GetPersonsRange(ListEditItemsRequestedByFilterConditionEventArgs args) {
    var skip = args.BeginIndex;
    var take = args.EndIndex - args.BeginIndex + 1;
    return (from person in DataHelper.Persons
            where (person.FirstName + " " + person.MiddleName + " " + person.LastName).ToLower().Contains(args.Filter.ToLower())
            orderby person.LastName
            select person
        )
        .Skip(skip)
        .Take(take);
}
public static object GetPersonByID(ListEditItemRequestedByValueEventArgs args) {
    if(args.Value != null)
        return GetPersonByID((int)args.Value);
    return null;
}

When a single item remains available after filter operations, the editor's SetSelectedIndex method automatically selects it in the editor's client-side EndCallback event handler.

Files to Review

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Use the combo box editor's BindList method to bind the editor to a large filtered data source.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •