using System;
using System.ComponentModel;
using System.IO;
using System.Web.UI.WebControls;
using SiberTek.Xenta.Presentation;
using SiberTek.Xenta.Presentation.Utils;
using SiberTek.Xenta.Utils;
using SiberTek.Xenta.Web.Server.Controls;
namespace SiberTek.Xenta.Web.Modules
{
public partial class TopicDropDownList : UserControlBase, IDropDownList<String>
{
#region Events
public event EventHandler SelectedIndexChanged;
#endregion
#region Properties
public bool AutoPostBack
{
get
{
return lstTopicList.AutoPostBack;
}
set
{
lstTopicList.AutoPostBack = value;
}
}
public bool AllowEmptyItem
{
get
{
return Convert.ToBoolean(ViewState["AllowEmptyItem"]);
}
set
{
ViewState["AllowEmptyItem"] = value;
}
}
[Browsable(false)]
public string SelectedValue
{
get
{
return lstTopicList.SelectedValue;
}
set
{
lstTopicList.SelectedValue = value;
}
}
public bool IsEmpty
{
get
{
return lstTopicList.Items.Count == 0;
}
}
public bool Enabled
{
set
{
lstTopicList.Enabled = value;
}
}
#endregion
#region Methods
public override void BindData()
{
try
{
string topicsDir = PathHelper.MapPath("Files/Topics/{0}/", LocalizationHelper.GetLanguageName(UserContext.Current.LanguageID));
if(AllowEmptyItem)
{
lstTopicList.Items.Add(new ListItem("-", String.Empty));
}
if(Directory.Exists(topicsDir))
{
foreach(string filepath in Directory.GetFiles(topicsDir, "*.xml"))
{
string topicname = Path.GetFileNameWithoutExtension(filepath);
lstTopicList.Items.Add(new ListItem(topicname, topicname));
}
}
lstTopicList.DataBind();
}
catch(Exception ex)
{
Page.ShowMessage(ex.Message);
}
base.BindData();
}
#endregion
#region Handlers
protected void LstTopicList_OnSelectedIndexChanged(object sender, EventArgs e)
{
FireSelectedIndexChangedEvent();
}
#endregion
#region Utilities
private void FireSelectedIndexChangedEvent()
{
if(SelectedIndexChanged != null)
{
SelectedIndexChanged(this, EventArgs.Empty);
}
}
#endregion
}
}