Find DataEditFormItem when using complex edit templates

2 posts, 0 answers
  1. Kenneth
    Kenneth avatar
    70 posts
    Member since:
    Feb 2008

    Posted 22 Jun 2009 Link to this post


    RadControls version


    .NET version


    Visual Studio version


    programming language


    browser support

    all browsers supported by RadControls

    When creating complex edit templates for RadGrid I found myself creating a lot of references like sender.Parent.Parent.Parent....etc. when trying to navigate from a control event back to the GridEditFormItem. I thought there had to be a better way. So, I created a simple templated class to navigate from a control through the control heirarchy to find the appropriate parent, based on the parent class. It works nicely for finding the GridEditFormItem in a templated edit form, but can be used for any other similar problems when navigating control hierarchies.

    As an example, if a button were included in a RadGrid edit template, you might get the reference to its GridEditFormItem like this...



    protected void Button1_Click(object sender, EventArgs e)  
        GridEditFormItem gridEditFormItem = (GridEditFormItem) ((Control)sender).Parent.Parent.Parent;  

    But using the FindIt class, you would use this notation... 




    protected void Button1_Click(object sender, EventArgs e)  
        GridEditFormItem gridEditFormItem = Find<GridEditFormItem>.Parent((Control)sender);  

    If you use the Parent.Parent.Parent... notation and you subsequently modified the edit template, for example, perhaps you put the button inside an asp:Panel, you would have to fix the reference as well, but with the Find<> notation it would work without modification.

    Its been a really useful addition to my toolkit, and helps separate code dependencies from edit template layout. I thought I'd share with others who might have similar issues.


  2. Yavor
    Yavor avatar
    11 posts

    Posted 24 Jun 2009 Link to this post

    Hi Kenneth,

    Thank you for sharing your approach with the community!
    I have updated your Telerik points for your involvement!

    Sincerely yours,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft R3 2016 release webinar banner
Back to Top