I supposed that this is about an ASP.NET application, so if is so the solution is the next one:
In your
Page_Init()
event you have to init your drop down list like in the next example:
protected void Page_Init(object sender, EventArgs e)
{
if (CurrentUser.UserRole == UserRoles.Administrator)
_editPopupControl.ShowCloseButton = true;
if (!Page.IsPostBack)
{
try
{
List<StoragePlan> itemsList = DataContext.StoragePlans.ToList<StoragePlan>();
Dictionary<string, int> dictionary = new Dictionary<string, int>();
foreach (StoragePlan storagePlan in itemsList)
{
if (!dictionary.ContainsValue(storagePlan.ID))
dictionary.Add(BaseListPage.GetEnumTextForValue(storagePlan.Type, typeof(StoragePlanTypes)), storagePlan.ID);
}
_storagePlanDropDownList.DataSource = dictionary;
_storagePlanDropDownList.DataValueField = "value";
_storagePlanDropDownList.DataTextField = "key";
_storagePlanDropDownList.DataBind();
_storagePlanDropDownList.Items.Insert(0, new ListItem(Resources.Resource.UserListPageNoStoragePlan, "-1"));
_storagePlanDropDownList.Items.Insert(0, new ListItem(Resources.Resource.UserListPageAllStoragePlan, "0"));
_storagePlanDropDownList.SelectedIndex = 0;
}
catch (Exception ex)
{
BosEventLog.LogException(ex);
this.ErrorMessage = Resources.Resource.EntityLoadError;
}
}
}
Then in could add a property in your class that return the selected value:
public int StoragePlanID
{
get
{
int entityID = 0;
if(_storagePlanDropDownList.SelectedItem != null)
int.TryParse(_storagePlanDropDownList.SelectedItem.Value, out entityID);
return entityID;
}
}