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;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With