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

Find DataEditFormItem when using complex edit templates

1 Answer 36 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kenneth
Top achievements
Rank 1
Kenneth asked on 22 Jun 2009, 07:59 PM

Requirements

RadControls version

2009.1.527.35

.NET version

2

Visual Studio version

2008

programming language

C#

browser support

all browsers supported by RadControls


PROJECT DESCRIPTION
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.

Regards,
Ken

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 24 Jun 2009, 11:03 AM
Hi Kenneth,

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

Sincerely yours,
Yavor
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.
Tags
Grid
Asked by
Kenneth
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or