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<T>() 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;
}
}
/// <summary>
/// Sets the selected entity.
/// </summary>
/// <param name="selectedItems">The selected items.</param>
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;
}
}
}
}