How to Bind Enum Types to the DropDownList?

后端 未结 6 1177
终归单人心
终归单人心 2020-12-24 11:29

If I have the following enum

public enum EmployeeType
{
    Manager = 1,
    TeamLeader,
    Senior,
    Junior
}

and I have DropDownList

6条回答
  •  北海茫月
    2020-12-24 12:14

    Here is another approach:

    Array itemNames = System.Enum.GetNames(typeof(EmployeeType));
    foreach (String name in itemNames)
    {
        //get the enum item value
        Int32 value = (Int32)Enum.Parse(typeof(EmployeeType), name);
        ListItem listItem = new ListItem(name, value.ToString());
        ddlEnumBind.Items.Add(listItem);
    }
    

    i used this link to do it:

    http://www.codeproject.com/Tips/303564/Binding-DropDownList-Using-List-Collection-Enum-an

提交回复
热议问题