Hi,
I am searching for a workaround to set the label and description property automatically from the display attribute even if the datafrom is not in the mode AutoGenerateFields=True. I started to create a custom control inherited from DataFormDataField and I was able to read out the correct values by reflection within the OnApplyTemplate event handler:
Unfortunately the properties are not displayed initially.
Is this in general a good approach for the problem? Where is the correct place (event) to execute the code?
Kind Regards
I am searching for a workaround to set the label and description property automatically from the display attribute even if the datafrom is not in the mode AutoGenerateFields=True. I started to create a custom control inherited from DataFormDataField and I was able to read out the correct values by reflection within the OnApplyTemplate event handler:
var dc = this.DataContext;
if(dc != null)
{
Type t =
dc.GetType();
PropertyInfo pi =
t.GetProperty(this.DataMemberBinding.Path.Path);
var attr
= pi.GetCustomAttributes(typeof(DisplayAttribute),
true).FirstOrDefault();
if(attr !=
null)
{
var
displayAttr = attr as
DisplayAttribute;
ResourceManager
rm = new
ResourceManager(displayAttr.ResourceType);
this.Label =
rm.GetString(displayAttr.Name);
this.Description = rm.GetString(displayAttr.Description);
}
}
Is this in general a good approach for the problem? Where is the correct place (event) to execute the code?
Kind Regards