Repeater
and
DataList
controls offer a quick and flexible means of displaying data on a ASPX page. But they offer no
paging functionality built in. The
DataGrid
control has in-built
paging but its structure is more rigid. There are several articles on various
ASP.NET Resource Sites that offer solutions, but I'm going to show you how to use the
PagedDataSource
class.
The
PagedDataSource
class encapsulates the properties of the
DataGrid
control that allow it to perform
paging. But we can use the class with
Repeater
and
DataList
controls to perform
paging in much the same way as a
DataGrid
.
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim myConnection As New _
SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
Dim myDA As New SqlClient.SqlDataAdapter("Select * from dtsDefect", _
myConnection)
myDA.Fill(ds, "t1")
pageds.DataSource = ds.Tables("t1").DefaultView
pageds.AllowPaging = True
pageds.PageSize = 4
Dim curpage As Integer
If Not IsNothing(Request.QueryString("Page")) Then
curpage = Convert.ToInt32(Request.QueryString("Page"))
Else
curpage = 1
End If
pageds.CurrentPageIndex = curpage - 1
lblCurrpage.Text = "Page: " + curpage.ToString()
If Not pageds.IsFirstPage Then
lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + _
"?Page=" + CStr(curpage - 1)
End If
If Not pageds.IsLastPage Then
lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + _
"?Page=" + CStr(curpage + 1)
End If
Repeater1.DataSource = pageds
Repeater1.DataBind()
End Sub