Paging ASP. NET DataList and DataRepeater provide a simple and quick way to show, in which we can use <ItemTemplate> is to enable us to control the emission style of the data at will! Unfortunately, they're not like the DataGrid, There is a built-in paging feature.
How to solve it?
In fact, we can "PagedDataSource" class to solve the paging problem.
Properties of the PagedDataSource class:
DataSource-Data source
Allowpaging-true whether paging is allowed.
PageSize-Number of items per page
PageCount-Total Pages
CurrentPageIndex-Current page index
The code is as follows:
<%@ Page language= "VB"%>
<%@ import namespace= "System.Data"%>
<script runat= "Server" >
Sub Page_Load (ByVal Sender as Object, ByVal e as EventArgs)
Dim Pgds as PagedDataSource = New PagedDataSource
Pgds.datasource = CreateDataSource (). DefaultView
pgds.allowpaging = True
Pgds.pagesize = 6
Lbltotalpage.text = Pgds.PageCount.ToString ()
Dim CurrentPage as Integer
If not Request.QueryString (' Page ') is nothing Then
CurrentPage = Convert.ToInt32 (Request.QueryString ("Page"))
Else
CurrentPage = 1
End If
If not Pgds.isfirstpage Then
Lnkprev.navigateurl = Request.currentexecutionfilepath + "? Page= "+ convert.tostring (CurrentPage-1)
End If
If not Pgds.islastpage Then
Lnknext.navigateurl = Request.currentexecutionfilepath + "? Page= "+ convert.tostring (currentpage + 1)
End If
Repeater1.datasource = Pgds
Repeater1.databind ()
End Sub
Function CreateDataSource () as Datatable
Dim DT as DataTable
Dim Dr as DataRow
Dim I as Integer
DT = New DataTable
Dt. Columns.Add (New DataColumn ("IntegerValue", GetType (Integer))
Dt. Columns.Add (New DataColumn ("StringValue", GetType (String))
Dt. Columns.Add (New DataColumn ("Datetimevalue", GetType (DateTime))
Dt. Columns.Add (New DataColumn ("Boolvalue", GetType (Boolean))
For i = 0 to 50
Dr = dt. NewRow ()
Dr (0) = i
DR (1) = "Item" + i.tostring ()
DR (2) = DateTime.Now.ToShortTimeString
If (i Mod 2 <> 0) Then
DR (3) = True
Else
DR (3) = False
End If
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.