Implement datalist and repeater Paging

Source: Internet
Author: User
The datalist or Repeater control can be displayed on multiple pages:
1. Write a method or stored procedure and return the data table (datatable) to be displayed based on the number of incoming pages)
2. Use the pageddatasource class (located in the namespace of system. Web. UI. webcontrols)

This articleArticleThis section describes how to use the pageddatasource class to display datalist and repeater controls by page. The pageddatasource class is also used inside the DataGrid Control. The pageddatasource class encapsulates the properties of the DataGrid control. These properties enable the DataGrid to execute pagination.

Some public attributes of the pageddatasource class:
Allowcustompaging gets or sets the value indicating whether to enable custom paging.
Allowpaging gets or sets the value indicating whether to enable pagination.
Count to obtain the number of items to be used from the data source.
Currentpageindex gets or sets the index of the current page.
Datasource obtains or sets the data source.
Cececount gets the number of items in the data source.
Firstindexinpage gets the first index on the page.
Iscustompagingenabled gets a value indicating whether to enable custom paging.
Isfirstpage gets a value indicating whether the current page is a homepage.
Islastpage gets a value indicating whether the current page is the last page.
Ispagingenabled gets a value indicating whether to enable paging.
Isreadonly gets a value indicating whether the data source is read-only.
Issynchronized gets a value indicating whether to synchronize access to the data source (thread safety ).
Pagecount obtains the total number of pages required for all items in the data source.
Pagesize gets or sets the number of items to be displayed on a single page.
Virtualcount gets or sets the actual number of items in the data source when custom pages are used.

Are these attributes similar to those of the DataGrid? Yes, the DataGrid control uses the pageddatasource class to display data by page. The following example shows how to use the pageddatasource class to display datalist and repeater controls by page:

Paging code
Public   Void Page_load (Object SRC, eventargs E)
{
Oledbconnection objconn = New Oledbconnection ( @" Provider = Microsoft. Jet. oledb.4.0; Data Source = c: \ test. MDB " );
Oledbdataadapter objcommand = New Oledbdataadapter ( " Select * from users " , Objconn );
Dataset DS = New Dataset ();
Objcommand. Fill (DS );

// Assign values to relevant attributes of the pageddatasource object
Pageddatasource objpps =   New Pageddatasource ();
Objpps. datasource = DS. Tables [ 0 ]. Defaultview;
Objpps. allowpaging =   True ;
Objpps. pagesize =   5 ;
Int Curpage;

// The current page is retrieved from the page query parameters
If (Request. querystring [ " Page " ] ! =   Null )
Curpage = Convert. toint32 (request. querystring [ " Page " ]);
Else  
Curpage = 1 ;

Objpds. currentpageindex = Curpage - 1 ;
Lblcurrentpage. Text =   " Page: "   + Curpage. tostring ();

If ( ! Objpps. isfirstpage)
Lnkprev. navigateurl = Request. currentexecutionfilepath +   " ? Page = "   + Convert. tostring (curpage - 1 );

If ( ! Objpps. islastpage)
Lnknext. navigateurl = Request. currentexecutionfilepath +   " ? Page = "   + Convert. tostring (curpage + 1 );

// Assign the pageddatasource object to the Repeater control
Repeater1.datasource = Objpps;
Repeater1.databind ();
}

Related Article

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.