文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>通用 Asp.Net DropDownList 绑定枚举类型 实例

通用 Asp.Net DropDownList 绑定枚举类型 实例

时间:2010-12-29  来源:Mr.Tom

/// <param name="li">第一项要显示的.eg:--请选择--</param>
/// <returns></returns>
public static void bindEnumList(DropDownList droplist, Type enumType, ListItem li)
{
    droplist.Items.Clear();
    if (enumType.IsEnum == false)
   {
        return;
    }
    droplist.Items.Add(li);

 

   Type typeDescription = typeof(DescriptionAttribute);
   System.Reflection.FieldInfo[] fields = enumType.GetFields();
   string strText = string.Empty;
   string strValue = string.Empty;
   foreach (FieldInfo field in fields)
   {
     if (field.IsSpecialName) continue;
     strValue = field.GetRawConstantValue().ToString();
     object[] arr = field.GetCustomAttributes(typeDescription, true);
     if (arr.Length > 0)
    {
       strText = (arr[0] as DescriptionAttribute).Description;
    }
    else
    {
       strText = field.Name;
    }

    droplist.Items.Add(new ListItem(strText, strValue));
  }

}

相关阅读 更多 +
排行榜 更多 +
XLM币最具爆发力的安全交易所欧易okex下载

XLM币最具爆发力的安全交易所欧易okex下载

金融理财 下载
XEM币最安全隐私链的全球交易所欧易okex下载

XEM币最安全隐私链的全球交易所欧易okex下载

金融理财 下载
WAVES币最新上线的优质交易所欧易okex下载

WAVES币最新上线的优质交易所欧易okex下载

金融理财 下载