Binding enumerations to the GridView

Raja
Posted by Raja under C# category on | Points: 50 | Views : 4315
To bind the enumerations to the GridView, you can use following code snippets.

You need to use following namespaces

using System.Collections;
using System.Collections.Generic;

GridViewPoints.DataSource = ToList(typeof(MyDepartment));
GridViewPoints.DataBind();


Here MyDepartment is the name of my enumeraitons.

// call this method as DataSource
    private ArrayList ToList(Type type)
{
ArrayList list = new ArrayList();
Array enumValues = Enum.GetValues(type);
int i = 1;
foreach (Enum value in enumValues)
{
list.Add(i + ". " + value.ToString());
i++;

}
return list;
}


Hope this will help somebody.

Thanks

Comments or Responses

Login to post response