枚举绑定DropDownList

//枚举

public enum Status{
        Open=1,
        Cancel=2,
        Close=3
}

//需引用System.Reflection库

using System.Reflection;

//页面初始化时绑定DropDownList

protected void Page_Load(object sender, EventArgs e)
{
        foreach (FieldInfo field in typeof(Status).GetFields())
         {
              if (!field.IsSpecialName)
              {
                  DropDownList1.Items.Add(new ListItem(field.Name, field.GetRawConstantValue().ToString()));
              }
         }
}

 

posted @ 2014-03-07 14:43  TJM  阅读(117)  评论(0)    收藏  举报