editTemplate findControl in gridView_RowCreated Event

I'm trying to set the .CommandArgument to the string representation of the RowIndex.

When I use FindControl, the ItemTemplate fields work fine, but the EditTemplate fields return null.

Can anyone offer some assistance to resolve this?

Ps, I'm using Visual Studio 2010 Professional, and ASP.NET 4.0 .NET Framework.
<asp:GridView ID="gvYourOpenJobs" 
                              EmptyDataText="No Jobs Found" onrowdatabound="gvYourOpenJobs_RowDataBound" onrowcreated="gvYourOpenJobs_RowCreated" AllowSorting="True" OnRowUpdating="gvYourOpenJobs_RowUpdating" AllowPaging="True">
                     <AlternatingRowStyle BackColor="#E9ECF1" ForeColor="RoyalBlue" />
                    <asp:TemplateField ShowHeader="False">
                          <asp:LinkButton ID="ButtonApprove" runat="server" CausesValidation="True" CommandName="Update" ForeColor="#009933" Text="Approve"></asp:LinkButton>
                          <asp:LinkButton ID="lBtnDeny" runat="server" CausesValidation="False" CommandName="Deny" ForeColor="#009933" Text="Deny"></asp:LinkButton>
                          <asp:LinkButton ID="lBtnCancel" runat="server" CausesValidation="False" CommandName="Cancel" ForeColor="Red" Text="Cancel"></asp:LinkButton>
                        <asp:LinkButton ID="lBtnApproveDeclineJob" runat="server" CausesValidation="False" CommandName="Edit" ForeColor="RoyalBlue" Text="Approve or Deny"></asp:LinkButton>

    protected void gvYourOpenJobs_RowCreated(object sender, GridViewRowEventArgs e)
        if (e.Row.RowType == DataControlRowType.DataRow)
            LinkButton selectButton = (LinkButton)e.Row.FindControl("btnYourOpenJobsSelect");
            if (selectButton != null)
                selectButton.CommandArgument = e.Row.RowIndex.ToString();

            LinkButton lBtnApproveDeclineJob = (LinkButton)e.Row.FindControl("lBtnApproveDeclineJob"); // ok
            if (lBtnApproveDeclineJob != null)
                lBtnApproveDeclineJob.CommandArgument = e.Row.RowIndex.ToString();

            LinkButton approveJob = e.Row.Cells[0].FindControl("ButtonApprove") as LinkButton; // returns null
            if (approveJob != null)
                approveJob.CommandArgument = e.Row.RowIndex.ToString();

            LinkButton denyJob = (LinkButton)e.Row.FindControl("lBtnDeny"); // returns null
            if (denyJob != null)
                denyJob.CommandArgument = e.Row.RowIndex.ToString();

            LinkButton cancelJob = e.Row.Cells[0].FindControl("lBtnCancel") as LinkButton; // returns null
            if (cancelJob != null)
                cancelJob.CommandArgument = e.Row.RowIndex.ToString();

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Easwaran ParamasivamCommented:
RowDataBound is the best place to find the controls.

protected void gvYourOpenJobs_RowDataBound(object sender, GridViewRowEventArgs e)
    if (e.Row.RowType == DataControlRowType.DataRow && 
        (e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit)
        // Find control
        LinkButton dl = (DropDownList)e.Row.FindControl("ButtonApprove");

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Easwaran ParamasivamCommented:
jackwebb22002Author Commented:
Yes, I remember that from last year when i initially built this application.  Sorry, but info in my brain has an expiration timer of about an hour!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.