C#遍历枚举,并绑定至类似DropDownList的控件上。
2010-07-17 10:30
483 查看
一、枚举
二、实现绑定的方法
#region GroupGrade:用户组等级 /// /// 用户组等级 /// public enum GroupGrade { /// /// 一级 /// 一级 = 1, /// /// 二级 /// 二级 = 2, /// /// 三级 /// 三级 = 3, /// /// 四级 /// 四级 = 4, /// /// 五级 /// 五级 = 5, /// /// 六级 /// 六级 = 6 } #endregion
二、实现绑定的方法
/// /// 对DropDownList对象执行数据绑定 /// /// 要绑定的DropDownList对象 /// 枚举类型 /// 默认值 /// 第一项提示字符 public static void DropDownList(ref DropDownList select, Type type, string value, string prompt) { select.Items.Clear(); if (prompt != null && prompt != "") { ListItem dl = new ListItem(prompt, ""); select.Items.Add(dl); } if (type != null) { int i = 0; string[] names = Enum.GetNames(type); foreach (int v in Enum.GetValues(type)) { ListItem li = new ListItem(names, v.ToString()); if (value == v.ToString()) li.Selected = true; select.Items.Add(li); } } }
三、使用示例 DropDownList(ref DropDownList1, typeof(GroupGrade), null, "选择等级");
相关文章推荐
- c#中DropDownList控件绑定枚举数据
- c#通过枚举自动生成绑定控件
- c#枚举类型在web控件CheckBoxList,RadioButtonList,DropDownList中的应用
- c# 用枚举绑定列表控件
- ASP.NET中DropDownList控件的数据绑定的C#语言描述
- ASP.NET中DropDownList控件的数据绑定的C#语言描述
- 枚举的转换、遍历和绑定到DropDownList
- DropDownList控件数据绑定
- C#遍历控件
- C# 程序中如何向(DEV)ComboBoxEdit控件中添加下拉列表的值不使用数据绑定,就是使用代码添加
- c# ComboBox 控件 用数据库填充 绑定
- 数据绑定控件收藏 DropDownList ListBox GridView DataList Repeater FormView DetailsView
- ASP.NET中DropDownList下拉框列表控件绑定数据的4种方法
- C# 遍历控件
- 枚举绑定到DropDownList
- C# 利用反射将枚举绑定到下拉框
- 将一个枚举类型动态绑定到一个列表控件的方法
- C# 遍历控件
- C#中DatagridView单元格动态绑定控件
- C# 遍历 HTML元素 遍历html控件