I am trying to bind an IList of objects to a GridView's DataSource and one of the properties of the object is an enum. I was trying to use a TypeConverter on the enum to use a Description when the object is bound to the GridView Row. It does not look like my EnumConverter.ConvertTo
method is being called. Will a TypeConverter be called automatically when the object is being bound to an ASP.NET GridView?
ENUM:
[TypeConverter(typeof(AuditReasonConverter))]
public enum AuditReason
{
[System.ComponentModel.Description("Successful Login")]
SuccessfulLogin,
[System.ComponentModel.Description("Failed Login")]
FailedLogin,
[System.ComponentModel.Description("New User")]
NewUser,
[System.ComponentModel.Description("Edited User")]
EditedUser
}
TypeConverter Class:
public class AuditReasonConverter : EnumConverter
{
public AuditReasonConverter()
: base(
typeof(Blah.Core.AuditItem.AuditReason))
{ }
public override object ConvertTo(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value,
System.Type destinationType)
{
if (destinationType == typeof(string))
{
return Utilities.GetEnumerationDescription(typeof(Blah.Core.AuditItem.AuditReason), value); // your code here
}
return base.ConvertTo(context, culture, value, destinationType);
}
}