Written by: Andy Sun
How to Use Paging with the .Net Repeater Control
One of the most common tasks when building ASP.NET web applications is displaying the data. When a web application contains high volume of data, paging functionality can help the user view web page easily and clearly. Unlike paging functionality built in ASP.Net DataGrid control, ASP.Net repeater control provides more user defined flexibility. The following code will show you how to create paging control in ASP.Net repeater control.
On the html page:
<html>
<head>
</head>
<body>
<form>
<table>
<tr>
<td align="center"><asp:hyperlink id="lnkPrev" Runat="server" text=" << Previous" Visible="False"></asp:hyperlink><asp:hyperlink id="lnkNext" Runat="server" Visible="False" Text=" Next >>"></asp:hyperlink>
</td>
</tr>
<asp:repeater id=”rptTemp” ruant=”server”>
<ItemTemplate>
<tr>
<td >
<asp:Label ID="lblID" Runat="server" text=’%#DataBinder.Eval(Container.DataItem, “ID")%>’</asp:Label>
</td>
<td >
<asp:Label ID="lblName" Runat="server" text=’%#DataBinder.Eval(Container.DataItem, “Name")%>’</asp:Label>
</td>
<td >
<asp:Label ID="lblDesc" Runat="server" text=’%#DataBinder.Eval(Container.DataItem, “Description")%>’</asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:repeater>
</table>
</form>
</body>
</html>
In the code behind:
Dim objPds As PagedDataSource = New PagedDataSource
Dim dv As DataView = New DataView(bindTable)’bindtalbe is a collection of data
objPds.DataSource = dv
objPds.AllowPaging = True
objPds.PageSize =10(‘how many data you wish to display)
If objPds.PageCount > 1 Then
lnkPrev.Visible = True
lnkNext.Visible = True
Dim curpage As Integer
If Not IsNothing(Request.QueryString("Page")) Then
curpage = Convert.ToInt32(Request.QueryString("Page"))
Else
curpage = 1
End If
objPds.CurrentPageIndex = curpage - 1
If Not objPds.IsFirstPage Then
lnkPrev.NavigateUrl = “currentpage” & "&Page=" & CStr(curpage - 1)
End If
If Not objPds.IsLastPage Then
lnkNext.NavigateUrl = “currentpage” & "&Page=" & CStr(curpage + 1)
End If
rptTemp.DataSource = objPds
rptTemp.DataBind()