开发者

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

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($st开发者_如何学编程mt, "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?


I would look into using the ASP.NET repeater control. Basically, you define a query for your items and assign it to the datasource of the repeater. From this, you can transform the data however you would like (links, images, li elements, etc). Please see the link below for more information. Read the entire article as .NET controls can be really nice, but have a lot to them and can be confusing somewhat especially coming from a scripting language (PHP, python, etc)

Repeater Control Information

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜