文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
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));
  }

}

相关阅读 更多 +
排行榜 更多 +
hacked

hacked

休闲益智 下载
佩科佩科的寿司手机版

佩科佩科的寿司手机版

休闲益智 下载
钓鱼好友

钓鱼好友

休闲益智 下载