How do I avoid .Parent.Parent.Parent. etc. when referencing control hierarchies?

LennywJ94

New Member
I'm trying to fix this ugly code.\[code\]RadGrid gv = (RadGrid) (((Control) e.CommandSource).Parent.Parent.Parent.Parent.Parent);\[/code\]I often need to find the first grid that is the parent of the parent of... etc of a object that just raised an event.The above tends to break when the layout changes and the number of .Parents increase or decreases.I don't necessarily have a control Id, so I can't use FindControl().Is there a better way to find the 1st parent grid?
 
Back
Top