using System; using System.Collections.Generic; using System.Text; using System.Web.UI.WebControls; using NHibernate; using RoomsHere.DataLayer; using RoomsHere.BusinessLayer; namespace RoomsHere.JabaControls { public class JabaDropDownList : DropDownList { public JabaDropDownList() : base() { //Standard for this framework. this.DataTextField = "DisplayText"; this.DataValueField = "Id"; } public T GetSelectedEntity() where T : class { if (this.SelectedValue == null) return null; long id = Convert.ToInt64(this.SelectedValue); ISession session = DL.SessionFactory.OpenSession(); using (session) { T entity = session.Load(typeof(T), id) as T; return entity; } } /// /// Sets the selected entity. /// /// The selected items. public void SetSelectedEntity(IPrimaryKey selectedItem) { if (selectedItem == null) return; this.SelectedIndex = -1; for (int i = 0; i < this.Items.Count; i++) { ListItem item = this.Items[i]; if (Convert.ToInt64(item.Value) == selectedItem.Id) item.Selected = true; } } } }