This is a migrated thread and some comments may be shown as answers.

display annotation

1 Answer 66 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Walter
Top achievements
Rank 1
Walter asked on 18 Oct 2011, 08:38 AM
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:

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

1 Answer, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 18 Oct 2011, 12:06 PM
Hi Daniel Koffler,

I have prepared an example project for you that illustrates a possible approach to achieving this task.  Please, refer to it and let us know whether such a solution meets your requirements.

Regards,
Ivan Ivanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Tags
DataForm
Asked by
Walter
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Share this question
or