The findcontrol () Templatefield I found that I always couldn't find it. I searched the internet and found that many of my friends encountered the same problem as me. In addition, many people on the Internet did not solve the problem well. I summarized it myself:
For Rowdatabound Find, you can useIf (E. Row. rowtype = datacontrolrowtype. datarow) to limit the range of find, because find is in Headertemplate . If the range is not limited Headertemplate If it is not found, null is returned, and an error occurs. datarow in the datacontrolrowtype enumeration determines that it is a data row.
The other is in Rowcommand I found that there are more friends with this problem than the previous one. In rowcommand, if you use the default gridview mode, E. commandargument is automatically set to the index of the row. In this case, you only need to specify gridview1.rows [convert. toint32 (E. commandargument)]. findcontrol ("XXX"), but if it is converted to template, E. commandargument does not automatically bind any value. You need to manually bind it. You can choose manually write commandargument =" <% # (gridviewrow) container ). rowindex %> ", bind the index of the row to the E. commandargument . many beginners do not understand why they want to do this here. In fact, I am also a beginner. Simply put, the rows are based on data loops, and each row has the same control, if you do not specify the row index, you can simply write gridview1.findcontrol ("XXX"). Ide does not know which control to look for, so you must specify the row number.