Home > Backend Development > C++ > How to Find a Control Within a GridView's ItemTemplate?

How to Find a Control Within a GridView's ItemTemplate?

DDD
Release: 2025-01-02 17:05:39
Original
974 people have browsed it

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;
    }
}
Copy after login

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;
    }
}
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template