Search code examples
c#asp.netgridviewfindcontrol

how to search a control in an asp.net gridview and access it?


I have a gridview as :

<asp:GridView ID="gvAppRejProfiles" runat="server" AutoGenerateColumns="false">
                        <Columns>
                            <asp:TemplateField>
                                <HeaderTemplate>
                                    Resumes
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:LinkButton ID="lbtnResumes" runat="server"></asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>

i have a list of resume names (string format) that i want to add as the text of the linkbutton "lbtnResumes" for all the resume names that i have in a string array.


Solution

  • make use of FindControl() mehod ....to search control

    void gvAppRejProfiles_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton bl = 
             (LinkButton)e.Row.FindControl("lbtnResumes");
    
    
        }
    }