Hi..
I m trying to create a custom textbox with a enum kind property in it(like textmode).the enum values will come from database..but enums cant be dynamic..is there another way out??
Hi..
I m trying to create a custom textbox with a enum kind property in it(like textmode).the enum values will come from database..but enums cant be dynamic..is there another way out??
Enums are compile-time constants. If the database values won't change at runtime, then you could always use a codegen tool to generate the enum values from the database (at pre-compile time). If they will change, you may need to just do a String Property or something similar, instead of the Enum.
You have to write a custom TypeConverter
to accomplish this duty.
public class MyItemsConverter : TypeConverter
{
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
StringCollection values = new StringCollection();
// Connect to database and read values.
return new StandardValuesCollection(values);
}
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return (context != null);
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return true;
}
}
public class MyControl : WebControl
{
[TypeConverter(typeof(MyItemsConverter))]
public string MyItem { get; set; }
}