Enum绑定DropDownList方法
方法:/// <summary>
/// 下拉列表绑定
/// </summary>
/// <param name="ddl"></param>
/// <param name="DataText"></param>
/// <param name="DataValue"></param>
private void ddlBind(DropDownList ddl, string[] DataText, int[] DataValue)
{
for (int i = 0; i < DataText.Length; i++)
{
ddl.Items.Add(new ListItem(DataText[i], DataValue[i].ToString()));
}
}
使用方法:
public enum LogType : int
{
/// <summary>
/// 错误 Value=0
/// </summary>
错误 = 0,
/// <summary>
/// 系统 Value=1
/// </summary>
系统 = 1
}
ddlBind(ddlLogType, Enum.GetNames(typeof(LogType)), (int[])Enum.GetValues(typeof(LogType)));