ASP.NET provides three powerful list controls: DataGrid, DataList, and Repeater controls, but only DataGrid controls provide paging feature. Relative to DataGrid, DataList, and Repeater controls have higher style customizers, many times we prefer to use the DataList or REPEATER control to display data.
Realizing the paging display of the DataList or Repeater control: 1
This article mainly said how to use the PageDataSource class to implement the paging display of the DataList and Repeater controls. The DataGrid control also uses the PagedDataSource class, the properties of the PageDataSource class package DataGrid control, which makes the DataGrid to perform paging.
Part of the PagedDataSource class: ALLOWCUSTompAGing Gets or sets the value indicating whether custom paging is enabled. ALLOWPAGING gets or sets the value indicating whether the paging is enabled. COUNT Gets the number of items to be used from the data source. CurrentPageIndex Gets or sets the index of the current page. DataSource gets or sets the data source. DataSourceCount Gets the number of items in the data source. FirstIndexInPage Gets the first index in the page. IScustomPagingeNableD gets a value that indicates whether custom paging is enabled. ISFirstPage gets a value that indicates whether the current page is homepage. IslastPage gets a value that indicates whether the current page is the last page. ISPagingeNabled gets a value that indicates whether paging is enabled. IsReadOnly gets a value indicating whether the data source is read-only. Issynchronized Gets a value indicating whether to synchronize access (thread security). PageCount Gets the number of pages required to display all items in the data source. PageSize Gets or Sets the number of items to display on a single page. VirtualCount Gets or settings the number of actual items in the data source when using custom paging.
Is these attributes similar to the property of DataGrid? That's right, the DataGrid control is to implement the data pagination display using the PagedDataSource class. The following is an example of the paging display of the DataList and Repeater controls using the PagedDataSource class:
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);
// related object attribute assignment PagedDataSource PagedDataSource objPds = new PagedDataSource (); objPds.DataSource = ds.Tables [0] .DefaultView; objPds.AllowPaging = true; objPds.PageSize = 5; int CurPage; // current page from Page Query Parameters Get if (Request.QueryString ["Page"]! = Null) CURPAGE = Convert.Toint32 (Request.QueryString ["Page"]); Else Curpage = 1;
Objpds.currentpageIndex = CURPAGE-1; lblcurrentpage.text = "Page:" CURPAGE.TOSTRING ();
If (! Objpds.isFirstPage) lnkprev.navigateurl = Request.currentexecutionFilePath "? Page =" Convert.toString (CURPAGE-1);
IF (! Objpds.islastPage) lnknext.navigateURL = Request.currentexecutionFilePath "? Page =" Convert.TOString (CURPAGE 1);
// Assign the PageDataSource object to the Repeater control REATER1.DATASOURCE = Objpds; Repeater1.DATABIND ();
This allows you to implement the paging display of the DataList and Repeater controls. But there is a disadvantage that every time you have to come out every time, DataGrid is the same, which will reduce a little efficiency (most of the time you can't figure out the difference); if you use the first method, you can only select SELECT Page data (implementation method, please see the article)
Mike from http://sunrise.szu.cn