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
- public partial class LandlordIndex : System.Web.UI.Page
- {
-
- string checkEmail = String.Empty;
-
- StringBuilder table = new StringBuilder();
- protected void Page_Load(object sender, EventArgs e)
- {
- checkEmail += Session["LandlordLogin"];
-
- if (Session["LandlordLogin"] != null)
- {
- lblWelcome.Text += Session["LandlordLogin"].ToString();
- }
- else
- {
- Response.Redirect("Login.aspx");
- }
- if (!Page.IsPostBack)
- {
-
- SqlConnection con = new SqlConnection();
- con.ConnectionString = ConfigurationManager.ConnectionStrings["rent-dbConnectionString1"].ToString();
- con.Open();
- SqlCommand comm = new SqlCommand();
-
- 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 + "'";
- comm.Connection = con;
- SqlDataReader rd = comm.ExecuteReader();
-
- table.Append("<table border='2' class='table table-striped table-bordered'>");
- table.Append("<tr><th>Property Number</th>");
- table.Append("<th>Address</th>");
- table.Append("<th>Number of Tenants</th>");
- table.Append("<th>Vacant?</th>");
- table.Append("<th>View</th>");
- table.Append("</tr>");
- if (rd.HasRows)
- {
- while(rd.Read())
- {
- table.Append("<tr>");
- table.Append("<td>" + rd[0] + "</td>");
- table.Append("<td>" + rd[1] + "</td>");
- table.Append("<td>" + rd[2] + "</td>");
- table.Append("<td>" + rd[3] + "</td>");
- table.Append("<td><a href=''>View</a></td>");
- table.Append("</tr>");
- }
- }
- table.Append("</table>");
- PlaceHolder1.Controls.Add(new Literal { Text = table.ToString() });
- rd.Close();
- }
- }