In the exam section, the need to add dynamic checkbox to allow users to choose whether to do the choice problem, or to do a judgment question, I in the DataList ItemDataBound event to add a checkbox to the DataList, in the interface can also show, I have a button outside the DataList, to loop through this DataList, to determine which user chose which, but the error came out, always "hold the object reference to the instance", with my experience, know that this is not found this control, find the wrong one afternoon, or can not find, Look carefully, looking for code errors, found no errors, but how can not find it, in looking for DataList events, found that will be in the Itemcreate event, the code copy to the Itemcreate event, in operation, it was successful, which I understand, Why the control has not been found, if the page is first accessed (Page.IsPostBack = False), then the first time the DataBind is executed, the ItemCreated event is fired first, that is, after the DataBind is executed, First the header line is built with itemcreated, then the header row is bound with ItemDataBound, then the first line is built with ItemCreated, then the itemdatabound is used to bind the first row, In other words, itemcreated and ItemDataBound are executed alternately.
When the page returns, the ItemCreated event is executed, before Page_Load, but the ItemDataBound event is no longer executed. If you want to add any controls dynamically in the DataList, you need to be in the ItemCreated event, not in the ItemDataBound event.