locked
How to change button text on RowDataBound? RRS feed

  • Question

  • User-1166428634 posted

    Hi All,

                My GridView control have a button Name "Click". What I am doing, on cliking on "Click" button I am changing status columns value to "True" Now, what my requirement is during redering my GridView control it have to check which rows status is "true" If it is then on GridView "Click" button's text should change to "Clicked".

                I have written code on RowDataBound event. But I unable to change Text of a button :

    Some code:

    GridView_RowDataBound :

    If(e.Rows.RowType==DataControlRowType.DataRow)
    {
      string btnName = e.Cells[6].Text;
    
      //Here, I want to change the button text which is on Column number 6
    }

    Thanks

    <script charset="UTF-8" src="chrome://hdv/content/hdv.js" type="application/javascript"></script>
    Thursday, February 13, 2014 9:59 PM

All replies

  • User-1716253493 posted
    Button btn = (Button)e.Row.FindControl("YourButtonID");
    btn.Text="xxxxx";

    or

    Button btn = (Button)e.Row.Cells[5].Controls[0];

    Thursday, February 13, 2014 10:26 PM
  • User-1166428634 posted

    I tried youe first code:

    There I had to convert the GridView Button into template field. and if i do so then some of mine RowCommand code not work.

    Then I wrote your second line of code like below :

     while (Global.reader.Read())
                {
                    if (Global.reader["Click"].Equals(true))
                    {
                        Button btnSold = (Button)e.Row.Cells[9].Controls[0];
                        btnSold.Text = "Clicked";
                        btnSold.CommandName = "Clicked";
                    }
                    else 
                    {
                        Button btnSold = (Button)e.Row.Cells[9].Controls[0];
                        btnSold.Text = "Click";
                        btnSold.CommandName = "Click";
                    }
                }   

    Here, I am reading the status dynamically from the Status column and accordingly I am trying to change the Button text... but not working.. :-(

    <script charset="UTF-8" src="chrome://hdv/content/hdv.js" type="application/javascript"></script>
    Saturday, February 15, 2014 5:20 AM
  • User-933407369 posted

    Can you provide any additional code or markup(page) related to this issue? i want to view your GridView html and check out them.

    At the same time, in order to help us to understand your issue better.

    Thank you for your understanding.

    Thursday, February 20, 2014 7:27 AM