My goal: I want to send any enum type and convert it to a List and bind it to a drop down list. i will use an ObjectDataSource as DataSource for the given drop down list. I want to create a composite control that only takes one parameter; enum type. The composite control will sort out databinding and all other bits and bops.

Now, the only problem I have is to convert the generic method to be compatible with the ObjectDataSource.

Here is the code for my current method that i need to use on my ObjectDataSource. So, this method is working fine and returns a list of items for the Enum type WeekDays. However, I need the same functionality, but I need to replace WeekDays with any type of enum.

As far as I know, I can't use a generic method with ObjectDataSOurce, but Generic Class is fine. I just can't get it to work with a generic class and all help is much appreciated. When all is working, I'll be happy to share the complete solution.

Alternative to Magnus', but the idea is pretty much exactly the same (just didn't want to throw it out after being beat to it ;-) ) - just iterates over the enum value rather than int. Same usage:

public static class DropDownData
{
// struct, IComparable, IFormattable, IConvertible is as close as we'll
// get to an Enum constraint. We don't actually use the constraint for
// anything except rudimentary compile-time type checking, though, so
// you may leave them out.
public static EnumDataItemList GetList<T>()
where T : struct, IComparable, IFormattable, IConvertible
{
// Just to make the intent explicit. Enum.GetValues will do the
// type check, if this is left out:
if (!typeof(T).IsEnum)
{
throw new ArgumentException("Type must be an enumeration");
}
EnumDataItemList items = new EnumDataItemList();
foreach (Enum e in Enum.GetValues(typeof(T)))
{
EnumDataItem items = new EnumDataItem();
// Note: This assumes the enum's underlying type is
// assignable to Int32 (for example, not a long):
int value = Convert.ToInt32(e);
// The same attribute retrieval code as in the
// WeekDays example, including:
item.Text = e.ToString(); // e is Enum here, no need for GetName
}
}
}