现在的位置: 首页 > 综合 > 正文

Enum 作为一个数据源绑定

2012年09月04日 ⁄ 综合 ⁄ 共 294字 ⁄ 字号 评论关闭

一个DropDwon和ListBox 绑定一个Enum的示例:代码如下所示:

1.选创一个Enum:

enum Speen
        { Low = 1, Mdeim = 2, High = 3 }

2.绑定数据:

protected void Page_Load(object sender, EventArgs e)
      {
          DropDownList1.DataSource = Enum.GetValues(typeof(Speen));
          DropDownList1.DataBind();
          ListBox1.DataSource = Enum.GetValues(typeof(Speen));
          ListBox1.DataBind();
      }

3.运行结果如下:

image

抱歉!评论已关闭.