I am writing my project on some page which is responsible for listing movies and after clicking on them it will link you to a page where you can see all about the specific movie you clicked Info, now that I am using SQL on my database, one of my ideas is to transfer the id of the pressed element after I have assigned the correct id to the hyperlink being clicked based on the movie you clicked. My question is how do I get the id of the content being clicked, transfer it to the backend so that I can pull the correct information from the database based on the same id. This is my code so far:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; namespace WebProject { public partial class movie : System.Web.UI.Page { public string movieLister = ""; protected void Page_Load(object sender, EventArgs e) { string fName = "contentDB.mdf"; string tableName = "moviesTbl"; string sqlSelect = $"select * from {tableName}"; DataTable table = Helper.ExecuteDataTable(fName, sqlSelect); int length = table.Rows.Count; for(int i = 0; i < length; i++) { movieLister += $""; } } } }{table.Rows[i]["rating"]}{table.Rows[i]["movieName"]}
This code essentially takes a list of movies and assigns the correct ID related to the movie description and sends it back to the page, the only thing I need to know is what to do to get the ID of which movie was clicked, So that I can transfer the correct information from the database to the page.
I've tried using multiple resources but none seem to help.
Since you didn't publish the page, I'm assuming you just spit out the
movieLister
string like this{%= movieLister %}
This should generate the format for thea
tag The same format you use in a for loop, like this:There are 2 issues with this HTML for what you want
div
tags without a beginning. This may be a typo, but will cause the browser's rendering engine to get very confused (and may also cause StackOverflow syntax highlighter)id
attribute that points to the movie ID, that information is not part of the URL that will be loaded when you click the link because it is not in thehref
attributeTo solve both problems, I will update the output html so that it looks like this: