How to create a list of data clickable? asp.net

Posted by Roger Filipe on Stack Overflow See other posts from Stack Overflow or by Roger Filipe
Published on 2010-05-27T18:11:27Z Indexed on 2010/05/27 18:51 UTC
Read the original article Hit count: 292

Filed under:
|

Hello, I am learning asp.net but I'm finding some problems. My doubt is how to make a list of titles of news contained in a database. And in this list, each of the titles when clicked is redirected to a page where you will be able to view the news in full (Title, Body, Author ..). What I got: - A database containing a table with the news, every news is associated with an identification code (ex: "ID"). - A page where you will make the listing. (Ex: site / listofnews.aspx) - I have a page that uses the method "querystring" to know what is the primarykey the news. (Ex: site/shownews.aspx?ID=12345, where "12345" is the primarykey of the news. Once it knows what is the primarykey of the news in the database, it loads each of the fields of the page (news.aspx) with the news, this part is working ok. - The data is retrieve using the Linq, so I receive a List of "News", the class "News" as ID, Title, Body, Author.. My doubt is how to make the listing clickable.

In php I used this method (make a list of html links, in each link the href field is changed so that the tag "id" coincides with the news):

//database used is oracle, $stmt is the query, you don´t need to understand how it works.
oci_define_by_name($stmt, "ID", $id);
oci_define_by_name($stmt, "TITLE", $title);
if (!oci_execute($stmt, OCI_DEFAULT)) {
    $err = oci_error($stmt);
    trigger_error('Query failed: ' . $err['message'], E_USER_ERROR);
}
echo '<br />';
while (oci_fetch($stmt)) {<------While there is data from the database , create links
$link = '<a href="site/shownews.php?ID='.$id.'" >'.$title.'</a>';<----the shownews.php?ID= $id, creates the link according with the ID
echo $link<---Prints the link
echo '<br />';
}

How do i make the same with asp.net?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about learning