title: Gridview changing text in a button column after data bind
body: <p>I have a GridView in a ASP.NET web application, in which I have added buttons in each row:</p>
  
  <pre><code>&lt;asp:GridView ID="gridviewdatadosen" runat="server" AutoGenerateColumns="False" CssClass="table table-striped table-bordered table-hover" OnRowDataBound="gridviewdatadosen_RowDataBound" OnSelectedIndexChanged="gridviewdatadosen_SelectedIndexChanged" OnRowCommand="gridviewdatadosen_RowCommand"&gt;
      &lt;Columns&gt;
          &lt;asp:BoundField DataField="NIK" HeaderText="NIK" SortExpression="NIK"&gt;&lt;/asp:BoundField&gt;
          &lt;asp:BoundField DataField="NIDN" HeaderText="NIDN" SortExpression="NIDN"&gt;&lt;/asp:BoundField&gt;
          &lt;asp:BoundField DataField="NAMA" HeaderText="NAMA" SortExpression="NAMA"&gt;&lt;/asp:BoundField&gt;
          &lt;asp:BoundField DataField="Alamat" HeaderText="Alamat" SortExpression="Alamat"&gt;&lt;/asp:BoundField&gt;
          &lt;asp:TemplateField ShowHeader="false"&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Button ID="btnstatus" runat="server" Text="Aktif" CssClass="btn btn-primary" CommandName="aktifasi"  CommandArgument='&lt;%# Eval("NIK") %&gt;'/&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
      &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>I fill the datagridview on the server side. I filled it with taking the data in the database.</p>
  
  <pre><code>                DataTable dt = new DataTable();
                  DataTable dt1 = new DataTable();
                  SqlConnection conn = new SqlConnection(@"Data Source=localhost;Initial Catalog=SKRIPSI;User ID=sa;Password=sa");
                  conn.Open();
                  string ngisi = "SELECT [nik] as 'NIK' , [nidn] as 'NIDN', [nama] as 'NAMA', [alamat] as 'Alamat' FROM [dosen]";
                  SqlCommand comm = new SqlCommand(ngisi, conn);
                  dt.Load(comm.ExecuteReader());
                  conn.Close();
                  gridviewdatadosen.DataSource = dt;
                  gridviewdatadosen.DataBind();
                  int tmp = dt.Rows.Count;
  </code></pre>
  
  <p>after I fill the datagridview, I wanted to check the status of dosen whether he is active or not by select id and status of dosen.</p>
  
  <pre><code>                conn.Open();
                  string check = "SELECT nik, status FROM [dosen]";
                  comm = new SqlCommand(check, conn);
                  dt1.Load(comm.ExecuteReader());
                  conn.Close();
  </code></pre>
  
  <p>I have tried to change the existing text on the button but did not succeed.</p>
  
  <pre><code>                        for (int i = 0; i &lt; tmp; i++)
                      {
                          if (dt1.Rows[i][1].ToString() == "Aktif")//check the dosen aktif or not
                          {
                              for (int j = 0; j &lt; tmp; j++)
                              {
                                  if (dt.Rows[j][0].ToString() == dt1.Rows[i][0].ToString())// check nik where status = 'Aktif'
                                  {
                                      // I want to change the button in each row. if he 'Aktif' then the text in button will change to be 'aktif'
                                      //do not know what to do
                                  }
                              }
                          }
                      }
  </code></pre>
  
  <p>I want to change the button in each row. if he 'Aktif' then the text in button will change to be 'aktif'. help me to solve this problem. Sorry if my english or my explain is bad. Thank You</p>