title: Delete button for each row in a table asp.Net C#
body: <p>I have been wrestling with this for days now. I have created a page with records selected from a database table. I need to create a button delete for each row. The requirement is to use mysql with Asp.Net and C#. Below is the select code:</p>
  
  <pre><code>//Show Data Method
          public void ShowData()
          {
              using (connection)
              {
                  using (var command = connection.CreateCommand())
                  {
                      command.CommandText = "SELECT CUST_ID,CUST_FNAME,CUST_SURNAME,CUST_DOB,CUST_GENDER,CUST_SMOKE_STATUS FROM customers";
  
                      connection.Open();
  
                      using (var reader = command.ExecuteReader())
                      {
                          var indexOfColumn1 = reader.GetOrdinal("CUST_ID");
                          var indexOfColumn2 = reader.GetOrdinal("CUST_FNAME");
                          var indexOfColumn3 = reader.GetOrdinal("CUST_SURNAME");
                          var indexOfColumn4 = reader.GetOrdinal("CUST_DOB");
                          var indexOfColumn5 = reader.GetOrdinal("CUST_GENDER");
                          var indexOfColumn6 = reader.GetOrdinal("CUST_SMOKE_STATUS");
  
                          htmlTable.Append("&lt;table class='table table-bordered table-hover table-responsive'&gt; ");
                          htmlTable.Append("&lt;tr style='background-color:#c7c7c7; color: White;'&gt;&lt;th&gt;Customer ID.&lt;/th&gt;&lt;th&gt;First Name&lt;/th&gt;&lt;th&gt;Last Name&lt;/th&gt;&lt;th&gt;Date of Birth&lt;/th&gt;&lt;th&gt;Gender&lt;/th&gt;&lt;th&gt;Smoker Status&lt;/th&gt;&lt;th&gt;Actions&lt;/th&gt;&lt;/tr&gt;");
  
                          while (reader.Read())
                          {
  
                              var value1 = reader.GetValue(indexOfColumn1);
                              var value2 = reader.GetValue(indexOfColumn2);
                              var value3 = reader.GetValue(indexOfColumn3);
                              var value4 = reader.GetValue(indexOfColumn4);
                              var value5 = reader.GetValue(indexOfColumn5);
                              var value6 = reader.GetValue(indexOfColumn6);
  
                              htmlTable.Append("&lt;tr&gt;");
                              htmlTable.Append("&lt;td&gt;" + value1.ToString() + "&lt;/td&gt;");
                              htmlTable.Append("&lt;td&gt;" + value2.ToString() + "&lt;/td&gt;");
                              htmlTable.Append("&lt;td&gt;" + value3.ToString() + "&lt;/td&gt;");
                              htmlTable.Append("&lt;td&gt;" + value4.ToString() + "&lt;/td&gt;");
                              htmlTable.Append("&lt;td&gt;" + value5.ToString() + "&lt;/td&gt;");
                              htmlTable.Append("&lt;td&gt;" + value6.ToString() + "&lt;/td&gt;");
                              htmlTable.Append("&lt;td&gt;" +
                              "&lt;form id='form1' runat='server' action = 'customerprofile.aspx'&gt;&lt;a href='customerprofile.aspx' class='btn btn-primary btn-xs' role='button'&gt;&lt;span class='button-links'&gt;&lt;i class='fa fa-folder-open'&gt;&lt;/i&gt;  View&lt;/span&gt;&lt;/a&gt; &lt;/form&gt;" +
                              "&lt;/td&gt;");
  
  
                              // now, do something what you want
                          }
                          htmlTable.Append("&lt;/tr&gt;");
                          htmlTable.Append("&lt;/table&gt;");
                          DBDataPlaceHolder.Controls.Add(new Literal { Text = htmlTable.ToString() });
  
  
                      }
                     // connection.Close();
                  }
              }
          }
  </code></pre>
  
  <hr>
  
  <h2>BELOW IS THE DATABASE TABLE:</h2>
  
  <pre><code>Customer_ID     First Name  Last Name    Age    Gender  Status   Action
  4903015744088   George      litsa        18     Male    N        Delete
  7208114443089   Kholie      Daliwe       19     Female  N        Delete
  7903155743090   Tankiso     Ramokoena    20     Male    Y        Delete
  7903015743091   Tiisetso    Masuku       21     Male    Y        Delete
  7903105443092   Sindiswa    Phaswana     22     Female  N        Delete
  7903113743093   Khanya      Gazi         23     Female  Y        Delete
  </code></pre>