using System.Collections.Generic; using System.Web.UI.WebControls; namespace DesignPatterns.Adapter { public class WebDropDownList : IDropDownListAdapter { public WebDropDownList( DropDownList dropDown ) { _dropDown = dropDown; } public void BindTo( IEnumerable< IDropDownListItem > pairs ) { if ( pairs != null ) { foreach ( IDropDownListItem pair in pairs ) { _dropDown.Items.Add( new ListItem( pair.Text, pair.Value ) ); } } } public IDropDownListItem SelectedItem { get { return new DropDownListItem( _dropDown.SelectedItem.Text, _dropDown.SelectedItem.Value ); } } private DropDownList _dropDown; } }