The FindControl method of the page class can be used to find any control inside a web form, regardless of its location in the page hierarchy. This includes controls that are nested inside other controls, such as controls within a GridView's TemplateField.
To find a control within a GridView's TemplateField, you can use the following steps:
In your code, you are trying to find the HyperLink control with the ID "hlPlus" within the ItemTemplate of the GridView's TemplateField. To do this, you can use the following code:
foreach (GridViewRow row in grvYourOpportunities.Rows) { if (row.RowType == DataControlRowType.DataRow) { // Get a reference to the HyperLink control. HyperLink hlPlus = (HyperLink)row.FindControl("hlPlus"); // Check if the HyperLink control was found. if (hlPlus != null) { // Do something with the HyperLink control. } } }
This code will iterate through the rows of the GridView and find the HyperLink control with the ID "hlPlus" within the ItemTemplate of the TemplateField. If the control is found, it will be assigned to the hlPlus variable. You can then use the hlPlus variable to do whatever you need to do with the control.
The above is the detailed content of How Can I Find a Control Within a GridView's TemplateField Using FindControl?. For more information, please follow other related articles on the PHP Chinese website!