summaryrefslogtreecommitdiff
path: root/DesignPatterns/src/app/DesignPatterns.Adapter/WebDropDownList.cs
blob: e356a71cabbd9f5cd1d7f677411d6372a982ff2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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;
	}
}