|
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