Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between Parent and NamingContainer in a Gridview

What is difference between these two statements? In particular, I'm interested in which one is more optimized.

GridViewRow currentItem = (GridViewRow)drp_Vendor.Parent;

and

GridViewRow currentItem = (GridViewRow)drp_Vendor.NamingContainer;
like image 397
Saroop Trivedi Avatar asked May 23 '13 08:05

Saroop Trivedi


1 Answers

The basic difference is that NamingContainer will navigate up the control tree until it finds an ancestor that is a naming container (implements the INamingContainer interface, while Parent will return the immediate parent in the control tree.

In your case, the GridViewRow appears to be both the immediate parent and the naming container of your drp_Vendor control.

But if, for example, you put your drp_Vendor control inside a Panel in a TemplateField, then the Parent will be the Panel while the NamingContainer will be the GridViewRow.

As for which is the "most optimized", the Parent property will be very slightly faster, but the difference will be insignificant.

like image 103
Joe Avatar answered Oct 07 '22 02:10

Joe