using System;
using System.ComponentModel;
using System.Web.UI.WebControls;
using SiberTek.Xenta.Enums;
using SiberTek.Xenta.Web.Controls;
using SiberTek.Xenta.Presentation.Resources;
namespace SiberTek.Xenta.Web.Home.Modules
{
public partial class PublicationTypeDropDownList : UserControlBase, IDropDownList<PublicationType?>
{
#region Events
public event EventHandler SelectedIndexChanged;
#endregion
#region Properties
[Browsable(false)]
public PublicationType? SelectedValue
{
get
{
return String.IsNullOrEmpty(lstPublicationTypeList.SelectedValue) ? (PublicationType?)null : (PublicationType)Enum.Parse(typeof(PublicationType), lstPublicationTypeList.SelectedValue);
}
set
{
lstPublicationTypeList.SelectedValue = value.HasValue ? value.Value.ToString() : String.Empty;
}
}
public bool AllowEmptyItem
{
get
{
return Convert.ToBoolean(ViewState["AllowEmptyItem"]);
}
set
{
ViewState["AllowEmptyItem"] = value;
}
}
public bool AutoPostBack
{
get
{
return lstPublicationTypeList.AutoPostBack;
}
set
{
lstPublicationTypeList.AutoPostBack = value;
}
}
public int ItemCount
{
get
{
return lstPublicationTypeList.Items.Count;
}
}
public bool Enabled
{
set
{
lstPublicationTypeList.Enabled = value;
}
}
#endregion
#region Methods
public override void BindData()
{
lstPublicationTypeList.Items.Clear();
if(AllowEmptyItem)
{
lstPublicationTypeList.Items.Add(new ListItem("-", String.Empty));
}
foreach(string name in Enum.GetNames(typeof(PublicationType)))
{
lstPublicationTypeList.Items.Add(new ListItem(StringManager.GetString("Home.PublicationType.{0}", name), name));
}
base.BindData();
}
#endregion
#region Handlers
protected void LstPublicationTypeList_OnSelectedIndexChanged(object sender, EventArgs e)
{
FireSelectedIndexChangedEvent();
}
#endregion
#region Utilities
private void FireSelectedIndexChangedEvent()
{
if(SelectedIndexChanged != null)
{
SelectedIndexChanged(this, EventArgs.Empty);
}
}
#endregion
}
}