Home >Backend Development >C++ >How to Find a Control Within a GridView's ItemTemplate?
This question is about how to find a Control if a control if that control is located inside a GridView Template, more specifically, ItemTemplate.
The code provided includes a hyperlink field inside GridView's Template Field (Item Template). However, when an attempt was made to retrieve the HyperLink's reference it failed.
To resolve this issue, one can use the foreach statement as seen below:
foreach(GridViewRow row in GridView1.Rows) { if(row.RowType == DataControlRowType.DataRow) { HyperLink myHyperLink = row.FindControl("myHyperLinkID") as HyperLink; } }
If the RowDataBound even is used, the code would be as follows:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if(e.Row.RowType == DataControlRowType.DataRow) { HyperLink myHyperLink = e.Row.FindControl("myHyperLinkID") as HyperLink; } }
The above is the detailed content of How to Find a Control Within a GridView's ItemTemplate?. For more information, please follow other related articles on the PHP Chinese website!