ASP NET programming problem realization Next and previous effect

Source: Internet
Author: User
Tags asp net

First is the Access database, there is a table called news, there are three fields, respectively Id,classid and name where ID is the primary key, ClassID can repeat now has the following data: ID classid name 1 1 my Test 1 2 2 my Test 2 3 2 My Test 3 4 1 My Test 4 5 2 my Test 5 6 3 My test 6 7 1 My test 7 8 2 My Test 8 question came, I want to achieve the effect of the previous and next article, assuming that the 5th news is now displayed as follows: My test 5 implements the following: previous: My Test 3 Next: My measurement Try 8 because the "my Test 5" ClassID is 2, so the classid of the previous and next article is also 2 this is very simple. You have to check 3 times in the query, the first query is the current record, 2nd, 3 times the query is the previous and the next record. So that should be 3 statements. SELECT * FROM news where Id=id select top 1 * from news where ID > ID and CLASSID=CLASSID ORDER by ID ASC SELECT top 1 * FROM news where ID < ID and classid=classid ORDER BY id DESC because ASCSS has no stored procedure, you may want to find out the current record first, take out the classification ID of this record, and then write the following 2 query words Sentence In the case of SQL Server, I will implement this function directly in the stored procedure. *******************************************************************************************

asp.net implementation of the next and previous effects C # complete code and stored procedure   

2011-01-19 00:32:34| Category: C # Learning | Report | Font size Subscription

C # code

Put 2 labels on the page to set NEXT1 and Up1.

private void Bindnewsupnextdata (int nnewsid)
{
News news = new News ();
Previous article
SqlDataReader Recup1 = news. Getsinglenewsup (NNEWSID);
if (recup1. Read ())
{
This.next1.Text = "Next article:" + "<a href=shownews.aspx?newsid=" + recup1["NewSID"]. ToString () + ">" + recup1["title"]. ToString () + "</a>";
}
Else
{
This.next1.Text = "Next article:" + "no longer";
}
Recup1. Close ();

Next article
SqlDataReader Recnext1 = news. Getsinglenewsnext (NNEWSID);
if (recnext1. Read ())
{
This.up1.Text = "prev:" + "<a href=shownews.aspx?newsid=" + recnext1["NewSID"]. ToString () + ">" + recnext1["title"]. ToString () + "</a>";
}
Else
{
This.up1.Text = "prev:" + "no more";
}
Recnext1. Close ();
}

SQL Server 2005 stored procedures:

PROCEDURE [dbo]. [Pr_news_single_next_get]
(
@NewsID int
)
As

SELECT

Xw_news.newsid,xw_news.title

From
Xw_news

WHERE

Newsid= (select min (NewsID) from Xw_news where newsid> @NewsID and categoryid=

(select CategoryID from xw_news where [email protected]))

PROCEDURE [dbo]. [Pr_news_single_up_get]
(@NewsID int
)
As

SELECT

Xw_news.newsid,xw_news.title

From
Xw_news

WHERE

Newsid= (select Max (NewsID) from Xw_news where newsid< @NewsID and categoryid=

(select CategoryID from xw_news where [email protected]))

ASP NET programming problem realization Next and previous effect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.