Michelle Carthy

Michelle Carthy

  • NA
  • 52
  • 11.6k

How to click on a link based on another cell in same row

Nov 16 2017 6:35 AM
I have a landlord table, tenant table and a property table in my database.I have a html table that is dynamically created which shows the properties of the landlord that is signed in.When a tenant signs up it enters the propery ID which is the foreign key in the tenant table. When I click the view link on that html table, I would like it to be redirected to a new page showing the tenants that belong to that property.. I am unsure how to do this when the view link is clicked based on the property id in that row
 
Here is my html table
 
 
and here is the code for the dynamically created table
  1. public partial class LandlordIndex : System.Web.UI.Page  
  2. {  
  3. //creating an empty string  
  4. string checkEmail = String.Empty;  
  5. //constructing a string called table that will be used to create a dynamic table  
  6. StringBuilder table = new StringBuilder();  
  7. protected void Page_Load(object sender, EventArgs e)  
  8. {  
  9. checkEmail += Session["LandlordLogin"];  
  10. //if session is not empty then show label with corresponding email used in log in  
  11. if (Session["LandlordLogin"] != null)  
  12. {  
  13. lblWelcome.Text += Session["LandlordLogin"].ToString();  
  14. }  
  15. else  
  16. {  
  17. Response.Redirect("Login.aspx");  
  18. }  
  19. if (!Page.IsPostBack)  
  20. {  
  21. //Creating a connection to my database using the connection string  
  22. SqlConnection con = new SqlConnection();  
  23. con.ConnectionString = ConfigurationManager.ConnectionStrings["rent-dbConnectionString1"].ToString();  
  24. con.Open();  
  25. SqlCommand comm = new SqlCommand();  
  26. //preparing a query which will select all properties matching the landlord that is logged in at that moment  
  27. comm.CommandText = "select p.Property_Id, p.Property_Address, p.Property_Num_Of_Tenants, p.Property_Vacant from Properties p inner join Landlords l On p.Landlord_Id = l.Landlord_Id where l.Landlord_Id = p.Landlord_Id and l.Landlord_Email = '" + checkEmail + "'";  
  28. comm.Connection = con;  
  29. SqlDataReader rd = comm.ExecuteReader();  
  30. //creating a table depending on the data that is selected from the query  
  31. table.Append("<table border='2' class='table table-striped table-bordered'>");  
  32. table.Append("<tr><th>Property Number</th>");  
  33. table.Append("<th>Address</th>");  
  34. table.Append("<th>Number of Tenants</th>");  
  35. table.Append("<th>Vacant?</th>");  
  36. table.Append("<th>View</th>");  
  37. table.Append("</tr>");  
  38. if (rd.HasRows)  
  39. {  
  40. while(rd.Read())  
  41. {  
  42. table.Append("<tr>");  
  43. table.Append("<td>" + rd[0] + "</td>");  
  44. table.Append("<td>" + rd[1] + "</td>");  
  45. table.Append("<td>" + rd[2] + "</td>");  
  46. table.Append("<td>" + rd[3] + "</td>");  
  47. table.Append("<td><a href=''>View</a></td>");  
  48. table.Append("</tr>");  
  49. }  
  50. }  
  51. table.Append("</table>");  
  52. PlaceHolder1.Controls.Add(new Literal { Text = table.ToString() });  
  53. rd.Close();  
  54. }  
  55. }

Answers (3)