Controllo DropDownList

Il controllo DropDownList permette di selezionare un valore a partire da una sorgente dati.
 
Personalizzazione
Possiamo impostare una sorgente dati personalizzata specificando il valore ControlClass per DataSourceMode e inserendo namespace e nome classe nella proprietà del controllo CustomControlClass.
 
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using DataWeb.Structure;
using DataWeb.Identity;
using DataWeb.Data;
using DataWeb.Data.Controls;
using DataWeb.WebApp.Infrastructure;
using Microsoft.Extensions.Localization;

namespace MyApp.DataWeb.Data.Controls
{
    public class Category_AreaName :  DropDownList
    {
        private readonly AreaRepository areaRepository;
        private readonly IStringLocalizer localizer;

        public Category_AreaName(Form form, IServiceProvider serviceProvider) : base(form, serviceProvider)
        {
            areaRepository = serviceProvider.GetService<AreaRepository>();
            localizer = serviceProvider.GetService<IStringLocalizer>();
        }

        public override async Task<IEnumerable<List.ListItem>> GetListValuesAsync(Dictionary<string, object> parameters, IUser user, string itemId = null, NavigationContext navigationContext = null)
        {
            var areas = await areaRepository.GetAreasAsync(new AreaRepository.Filter(), "en-US");

            return areas.Select(x => new List.ListItem { Title = x.Name, Value = x.Name });
        }
    }
}