请教:数据库里面的枚举类型的值,由于在表现层是用的GridView绑定的DataSet,在后台代码里面就不能控制它的输出了;这样页面显示的就是枚举类型的int值,我想知道怎么样才能返回真实的枚举值。谢谢。

解决方案 »

  1.   

    一种做法是把这些枚举写到数据库中,作为数据字典,在sql查询时关联查出另一种做法就是在GridView得帮定事件中处理,如datagrid
    private void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
    if (e.Item.ItemType!=ListItemType.Header)
    {
        string subject=Enum.GetName(typeof(EnumActivityType), Convert.ToInt32(DataBinder.Eval(e.Item.DataItem,"type")),
        e.Item.Cells[4].Text=subject;
    }
    }
    public enum EnumActivityType
    {
                Task = 1,
                Fax = 2,
                Phone = 3,
                Email = 4,
                Reminder = 5,
                Appointment = 6,
                Expiration = 7,
                Inquiry = 8
    }