从表单到类的访问控制值。 [英] Access Control values from form to class.
本文介绍了从表单到类的访问控制值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个默认页面和一个类。
我想从默认页面到我的班级获取下拉列表的值。
我该怎么做呢,
我是OO编程的新手
I have a default page and a class.
I want to get the value of the dropdownlist from default page to my class.
how can I do this,
I'm new at OO programming
推荐答案
我认为这是关于一个ASP.NET应用程序,所以如果是这样的解决方案是下一个:
在您的Page_Init()
事件中,您必须初始化下拉列表,如下例所示:
I supposed that this is about an ASP.NET application, so if is so the solution is the next one:
In yourPage_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
{
//
// Init the center drop down list used as filter control
//
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;
}
}
这篇关于从表单到类的访问控制值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文