Use repeater and pagedatasource in Asp.net to implement paging code

Source: Internet
Author: User

CopyCode The Code is as follows: pageddatasource objpage = new pageddatasource ();

Dataview DV = bllbook. getlistbystate ("", true );
// Set the data source
Objpage. datasource = DV;

// Allow Paging
Objpage. allowpaging = true;

// Set the number of items displayed on each page
Objpage. pagesize = 10;

// Define variables to save the index of the current page
Int curpage;
Int recordcount;
Int pagecount = objpage. pagecount;

Recordcount = DV. count;

// Determine whether a page Jump request exists
If (request. querystring ["page"]! = NULL)
{
Curpage = convert. toint32 (request. querystring ["page"]);
}

Else
{
Curpage = 1;
}

// Set the index of the current page
Objpage. currentpageindex = curpage-1;

// Display status information
Lblcurpage. Text = "" + curpage. tostring () + "/" + pagecount. tostring () + "Page total" + recordcount. tostring () + "record ";

// If the current page is not the homepage
If (! Objpage. isfirstpage)
// Define the URL of the hyperlink "Previous Page" as the virtual path of the current execution page, and pass the index value on the next page
{
Lnkprev. navigateurl = request. currentexecutionfilepath + "? Page = "+ convert. tostring (curpage-1 );
Lnkfirst. navigateurl = request. currentexecutionfilepath + "? Page = "+ convert. tostring (1 );
}

// If the current page is not the last page
If (! Objpage. islastpage)
// Define the URL of the "next page" hyperlink as the virtual path of the current execution page, and pass the index value on the next page
{
Lnknext. navigateurl = request. currentexecutionfilepath + "? Page = "+ convert. tostring (curpage + 1 );
Lnklast. navigateurl = request. currentexecutionfilepath + "? Page = "+ convert. tostring (pagecount );
}

// Bind data
Repeater1.datasource = objpage;
Repeater1.databind ();

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.