user3158622
user3158622

Reputation: 23

trying to find control which is inside gridview which happens to be inside a repeater.

So I have a repeater which has a gridview in it. I need to find a hyperlink field that is inside the gridview. I am able to find the gridview using the following code, but then when I try to find the hyperlink inside that gridview, my program crashes.

protected void CompletedRepeater_DataBound(object sender, RepeaterItemEventArgs e)
{
    Repeater rpt = (Repeater) sender;
    if (e.Item.ItemType == ListItemType.Item 
        || e.Item.ItemType == ListItemType.AlternatingItem)
    {

            GridView gv = (GridView)e.Item.FindControl("CompletedGridr");
            if (gv != null)
            {
            }

    }
}

With the above code I am able to find the gridview.

I want to find the hyperlink inside the

if (gv != null)
            {

block.

Any ideas on how I can achieve this?

Upvotes: 0

Views: 237

Answers (1)

Ehsan Sajjad
Ehsan Sajjad

Reputation: 62488

Do something like this:

foreach(GridViewRow row in gv.Rows)
{

HtmlGenericControl linkTag= row.FindControl("linktag") as HtmlGenericControl;

}

or you can do like this if you are using <asp:HyperLink> :

HyperLink myHyperLink = row.FindControl("myHyperLinkID") as HyperLink;

Upvotes: 2

Related Questions