asp.net 枚举文件里面的数字绑定到DropDownList里面去 复制代码 代码如下:public class AppEnum { public enum PointLogType : int { /// /// Email确认 /// [Description("Email确认")] Recruit = 1, //新客户激活+ /// /// 老客户回馈 /// [Description("老客户回馈")] Veteran = 2, //老客户购物历史回复 /// /// 生成订单 /// [Description("生成订单")] CreateOrder = 3, //下订单- /// /// 作废订单 /// [Description("作废订单")] AbandonSO = 5, //作废订单 /// /// 作废订单取消 /// [Description("作废订单取消")] CancelAbandonSO = 6, //审核作废取消- /// /// 退货 /// [Description("退货")] ReturnProduct = 7, //退货- /// /// 取消退货 /// [Description("取消退货")] CancelReturn = 8, /// /// 取消出库 /// [Description("取消出库")] CancelOutstock = 9, //取消出货 /// /// 积分转移 /// [Description("积分转移")] TransferPoint = 10, //积分转移 /// /// 购物得分 /// [Description("购物得分")] AddPointLater = 11, //滞后加分 /// /// 订单修改 /// [Description("订单修改")] UpdateSO = 12, //修改SaleOrder /// /// 批发扣除 /// [Description("批发扣除")] WholeSale = 13, //批发减分-, 好象没有使用。 /// /// 买卡 /// [Description("买卡")] InfoProduct = 14, //买卡减分- /// /// 其他 /// [Description("其他")] BizRequest = 15, //Request /// /// 商品评论送积分 /// [Description("商品评论送积分")] Remark = 16, //Remark /// /// 注册送积分 /// [Description("注册送积分")] NewRegister = 17, //注册送积分 /// /// DIY活动积分增减 /// [Description("DIY活动积分增减")] DIY = 18, //DIY活动积分增减, 成都DIY系统,没有用起来。 /// /// 系统转移积分 /// [Description("系统转移积分")] SysTransferPoint = 19, //系统帐号neweggcs转移积分给客户 /// /// 系统帐号增加积分 /// [Description("系统帐号增加积分")] AddPointToSysAccounts = 20, //财务给系统帐号增加积分 /// /// 参加竞猜 /// [Description("参加竞猜")] BetReductPoint = 21, //下注使用积分 /// /// 竞猜所得 /// [Description("竞猜所得")] BetAddPoint = 22, //开奖得积分 /// /// 新用户第一次购物赠送积分 /// [Description("新用户第一次购物赠送积分")] NewCustomerFirstBuy = 23, //新注册用户,第一次购物送积分 /// /// 自动提升精华赠送积分 /// [Description("自动提升精华赠送积分")] SetScoreAuto = 24, //自动提升精华赠送积分 /// /// 市场促销活动增送积分 /// [Description("市场促销活动增送积分")] MKTCampaign = 25, /// /// 到期回收积分 /// [Description("到期回收积分")] DisusePoint = -1 } } 上面是一个枚举列表,怎么去读取呢?用一个DDR来绑定呢? 复制代码 代码如下:ddlType.DisplayMember = "Value"; ddlType.ValueMember = "Key"; ddlType.DataSource = CommonFunctions.GetEnumItems(typeof(AppEnum.PointLogType), false); ddlType.SelectedValue = 25; // 默认值下面是CommonFunctions里面的GetEnumItems方法:复制代码 代码如下:/// /// 获得枚举类型所包含的全部项的列表。 /// /// 枚举的类型 /// 是否包含"All" /// public static List GetEnumItems(Type enumType, bool withAll) { List list = new List(); if (enumType.IsEnum != true) { // 不是枚举类型 throw new InvalidOperationException(); } // 包含 All 选项 if (withAll == true) list.Add(new EnumItem(AppConst.IntNull, "All")); // 获得特性Description的类型信息 Type typeDescription = typeof(DescriptionAttribute); // 获得枚举的字段信息(因为枚举的值实际上是一个static的字段的值) System.Reflection.FieldInfo[] fields = enumType.GetFields(); // 检索所有字段 foreach (FieldInfo field in fields) { // 过滤掉一个不是枚举值的,记录的是枚举的源类型 if (field.FieldType.IsEnum == false) continue; // 通过字段的名字得到枚举的值 int value = (int)enumType.InvokeMember(field.Name, BindingFlags.GetField, null, null, null); string text = string.Empty; // 获得这个字段的所有自定义特性,这里只查找Description特性 object[] arr = field.GetCustomAttributes(typeDescription, true); if (arr.Length > 0) { // 因为Description自定义特性不允许重复,所以只取第一个 DescriptionAttribute aa = (DescriptionAttribute)arr[0]; // 获得特性的描述值 text = aa.Description; } else { // 如果没有特性描述,那么就显示英文的字段名 text = field.Name; } list.Add(new EnumItem(value, text)); } return list; } public class EnumItem { private object m_key; private object m_value; public object Key { get { return m_key; } set { m_key = value; } } public object Value { get { return m_value; } set { m_value = value; } } public EnumItem(object _key, object _value) { m_key = _key; m_value = _value; } }