display annotation

2 posts, 0 answers
  1. Walter
    Walter avatar
    22 posts
    Member since:
    Jun 2009

    Posted 18 Oct 2011 Link to this post


    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 =
    PropertyInfo pi = 
    var attr 
    = pi.GetCustomAttributes(typeof(DisplayAttribute), true).FirstOrDefault();
    if(attr != 
    displayAttr = attr as DisplayAttribute;
    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

  2. Ivan Ivanov
    Ivan Ivanov avatar
    1114 posts

    Posted 18 Oct 2011 Link to this post

    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.

    Ivan Ivanov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. DevCraft R3 2016 release webinar banner
Back to Top