[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1200
  • Last Modified:

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?
0
mbart
Asked:
mbart
2 Solutions
 
JimBrandleyCommented:
Have you tried it like this:
                (ButtonField)(e.Row.Cells[3].Controls[0]).Text = "View/Cancel";

Jim
0
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now