'Check table row number on button click

Hi i've this code and in for each part i create a table with 3 cells (name, timestamp and operation with a button view). I see some elements in this table, but when i click the button "VIEW" i want to know the id or number of the row clicked. This is the code:

  protected void Page_Load(object sender, EventArgs e)
        {
            List<myproject> items = new List<myproject>();
            string session = (string)Session["username"];
            string id_login = "";

            using (SqlConnection sqlCon = new SqlConnection(@"Data Source=DESKTOP-9UN2C31;Initial Catalog=projectdatabase;Integrated Security=True"))
            {
                sqlCon.Open();
                string query1 = "SELECT id FROM dbo.login WHERE username=@username";
                SqlCommand sqlCmd1 = new SqlCommand(query1, sqlCon);
                sqlCmd1.Parameters.AddWithValue("@username", session);
                SqlDataReader rdr1 = sqlCmd1.ExecuteReader();

                    while (rdr1.Read())
                    {
                        id_login = rdr1.GetString(0);
                    }
                     rdr1.Close();

                    string query = "SELECT nome, timestamp FROM dbo.project WHERE id_login=@id_login";
                    SqlCommand sqlCmd = new SqlCommand(query, sqlCon);
                    sqlCmd.Parameters.AddWithValue("@id_login", id_login);


                    using (var rdr = sqlCmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            items.Add(new myproject { nome = (string)rdr["nome"], timestamp = (string)rdr["timestamp"]});
                            

                        }
                        rdr.Close();

                    }
                }

                foreach (var element in items)
                {
                    Button b = new Button();
                    b.Text = "VIEW";
                    TableRow tr = new TableRow();
                    TableCell tc1 = new TableCell();
                    TableCell tc2 = new TableCell();
                    TableCell tc3 = new TableCell();
                    tc1.Controls.Add(new LiteralControl("<span>" + element.nome + "</span>"));
                    tc2.Controls.Add(new LiteralControl(element.timestamp));
                    tc3.Controls.Add(b);
                

                    tr.Controls.Add(tc1);
                    tr.Controls.Add(tc2);
                    tr.Controls.Add(tc3);
                    Table1.Controls.Add(tr);
                    System.Diagnostics.Debug.WriteLine(element.nome + " " + element.timestamp);

                }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source