Last post Mar 04, 2014 10:12 PM by Shawn - MSFT
Mar 04, 2014 05:09 AM|heron6|LINK
I am new to VB and im having issues hiding and showing a check box with a gridview. I am being displayed with the error 'NullReferenceException was unhandled by user code' at the line of the code 'Chk.Visible =
help would be great
Mar 04, 2014 05:13 AM|AidyF|LINK
Mar 04, 2014 07:51 AM|oned_gk|LINK
Mar 04, 2014 10:12 PM|Shawn - MSFT|LINK
For this situation, the above codes couldn't get the dropdownlist. And you could refer to the following information:
GridView is a control which repeats its rows based on the bound data, e.g in practise it creates a set of controls (one row in it) as many times as there are rows in data source. In order to keep IDs of these controls unique, GridView and its rows are naming
containers (implement INamingContainer interface). Being a naming container means that a control provides a new naming scope for its child controls by appending it's ID into ID of its own naming container.
And being a naming container means that in order to look for a control with its local ID (not the unique id) you need to run FindControl against its naming container. In this case you run it againt GridView but GridView is
not the direct naming container (or parent) of the HiddenField but
the corresponding row (GridViewRow) is.
Besides, you could also refer to: