TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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
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();
}
}
Reply
Answers (
3
)
How to Create Printer Drivers
c# Divide operation Not working