私は、データベースにテナントテーブルとテナントテーブルを持っています。私は動的に作成されたhtmlテーブルを持っています。テナントがサインアップすると、それはテナント表の外部キーであるプロパティIDを入力します。そのHTMLテーブルのビューリンクをクリックすると、そのプロパティに属するテナントを示す新しいページにリダイレクトされます。プロパティIDに基づいてビューリンクがクリックされたときにこれを行う方法がわかりませんその行ここ同じ行の別のセルに基づくリンクをクリックする方法C#asp.net
This is my html table とで動的に作成されたテーブル
public partial class LandlordIndex : System.Web.UI.Page
{
//creating an empty string
string checkEmail = String.Empty;
//constructing a string called table that will be used to create a dynamic table
StringBuilder table = new StringBuilder();
protected void Page_Load(object sender, EventArgs e)
{
checkEmail += Session["LandlordLogin"];
//if session is not empty then show label with corresponding email used in log in
if (Session["LandlordLogin"] != null)
{
lblWelcome.Text += Session["LandlordLogin"].ToString();
}
else
{
Response.Redirect("Login.aspx");
}
if (!Page.IsPostBack)
{
//Creating a connection to my database using the connection string
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["rent-dbConnectionString1"].ToString();
con.Open();
SqlCommand comm = new SqlCommand();
//preparing a query which will select all properties matching the landlord that is logged in at that moment
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();
//creating a table depending on the data that is selected from the query
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();
}
}
}
を必要とする場合には私に知らせない代わりにそのような文字列を生成するデータを表示するためのGridViewを使用してください。 – VDWWD
@VDWWDのようなGridViewを使用するのではなく、動的に生成されたテーブルを使用する特別な理由はありますか? –