DataList and DataRePeater in ASP.NET provide simple and quick ways to display, between them, we can use
What makes us can emissions from the control data you want! Unfortunately, they don't have a built-in paging function as DataGrid.
How to solve it?
In fact, we can [PageDataSource] class to solve the problem of paging.
The properties of the PagedDataSource class:
DataSource - Data Source
AllowPaging - True is allowed to paginize.
Pagesize - Number of items per page
PageCount - Total number of pages
CurrentPageIndex - current page of the page
code show as below:
<% @ Page language = "vb"%>
<% @ Import namespace = "system.data"%>
??? Sub Page_Load (Byval E AS Object, ByVal E As Eventargs)
?
??????? DIM PGDS as pagedataource = new pagedataserce
??????? 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
??????? endiff
?
??????? pgds.currentpageindex = currentpage - 1
??????? lblcurrentpage.text = currentpage.tostring ()
?
??????? if not pgds.isfirstpage the
??????????? lnkprev.navigateURL = Request.currentexecutionFilePath "? Page =" Convert.TOSTRING (CURRENTPAGE - 1)
??????? endiff
?
??????? if not pggds.islastpage thein
??????????? LNKNEXT.NAVIGATEURL = Request.currentexecutionFilePath "? Page =" Convert.TOSTRING (CurrentPage 1)
??????? endiff
?
??????? repeater1.datasource = PGDS
??????? rebeater1.databind ()
?
??? End Sub
?
Function CreateDataSource () AS DataTable
?
DIM DT AS DATATABLE
DIM DR AS DATAROW
DIM I AS Integer?
??????? dt = new dataable
??????? 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
?
Dt.Rows.Add (DR)
NEXT
?
Return DT
?
END FUNCTION
?
script>
?
Body {
FONT: 10PX Verdana, Arial, Helvetica, "Sans Serif"; Color: # 000000;
}
.TXT {
Font-size: 12px
}