Binding enumerations to the GridView

Posted by Raja under C# category on | Points: 50 | Views : 4261
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));

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());

return list;

Hope this will help somebody.


Comments or Responses

Login to post response