ASP.NET 下拉列表绑定枚举类型值,不用再新建一个枚举表

public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GetListType();
} private void GetListType()
{
DropDownListMenu.Items.Clear();
DropDownListMenu.DataSource = ListTypeForEnum();
DropDownListMenu.DataValueField = "Value";
DropDownListMenu.DataTextField = "Text";
DropDownListMenu.DataBind();
}
public static IList ListTypeForEnum()
{
ArrayList list = new ArrayList();
foreach (int i in Enum.GetValues(typeof(EnumActivityType)))
{
ListItem listitem = new ListItem(Enum.GetName(typeof(EnumActivityType), i), i.ToString());
list.Add(listitem);
}
return list;
}
public enum EnumActivityType
{
[Description("测试1")]//将枚举值直接转为中文
Task = ,
Fax = ,
Phone = ,
Email = ,
Reminder = ,
Appointment = ,
Expiration = ,
Inquiry =
}
}
 
上一篇:5332盛照宗 如何获取新技能+c语言学习调查


下一篇:B1816 扑克牌 二分答案 + 贪心