Trying to change the TEXT on a Button Field throws error

I am trying to change the Text value of a Button at runtime with following code.
if (e.Row.RowType == DataControlRowType.DataRow)
        {
           if (GridView3.DataKeys[e.Row.RowIndex].Value.ToString() == "1")
            {
                         
                ((ButtonField)e.Row.Cells[3].Controls[0]).Text = "View/Cancel";
            }

        }
But throws error on page build.  What am I missing?
mbartAsked:
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.

JimBrandleyCommented:
Have you tried it like this:
                (ButtonField)(e.Row.Cells[3].Controls[0]).Text = "View/Cancel";

Jim
0

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
mbartAuthor Commented:
When I try that it throws the following error

Cannot convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.ButtonField'
0
JimBrandleyCommented:
Try taking the cas out, as:
               (e.Row.Cells[3].Controls[0]).Text = "View/Cancel";

Jim
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

JimBrandleyCommented:
Disregard my last - I do not think that will work. I'll keep looking...

Jim
0
JimBrandleyCommented:
Do you have more that one control in that column?

Jim
0
gregoryyoungCommented:
sounds like Cells[3] is not a button field... when you look in a debugger what does it tell you the type is?

You are either getting the wrong column or the column you have isn't a ButtonField
0
mbartAuthor Commented:
Thanks for all the effort.  I will be posting another question along similar lines if you care to assist me again.
0
monarch_ilhanCommented:
Is the columns which the button reside, Template column or a Bound column. If it is template you can do below
((ButtonField)(e.Row.Cells[3].FindControl("btnControlName")).Text="New Text";

0
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
Web Applications

From novice to tech pro — start learning today.