How to use PagedDataSource to do DataRepeater's page effect

Source: Internet
Author: User
Tags date datetime eval integer tostring
Asp. NET, DataList and DataRepeater provide a simple and quick way to show the data,
<ItemTemplate> is a way for us to decide what we want to do with our data. Unfortunately, he
Unlike the DataGrid, there is a built-in paging function.

How do you solve this problem that cannot be divided into pages? In this article, we will introduce how to use PagedDataSource Class to solve the problem of the page.

Simple introduction to a few commonly used PagedDataSource Class public Properties

DataSource-Data source
Allowpaging-true allow a page to be allowed to be false.
PageSize-How many times did you decide to repeat
PageCount-A total of several pages
CurrentPageIndex-Current Pages
Isfirstpage-is the first page, echo True or False
Islastpage-Is it the last page, echo True or False

Here's the example (you can just run away with the clippings)

--------------------------------------------------------------------------------

<%@ Page language= "VB"%>
<%@ import namespace= "System.Data"%>
<script runat= "Server" >
Sub Page_Load (Sender as Object, E as EventArgs)

Dim Pgds as PagedDataSource = New PagedDataSource ()
Pgds.datasource = CreateDataSource (). DefaultView
pgds.allowpaging = True
Pgds.pagesize = 6 ' Deciding how many times to duplicate
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

Pgds.currentpageindex = CurrentPage-1
Lblcurrentpage.text = "Page:" + currentpage.tostring ()

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

' This is a example from ASP.net QuickStart
' You can change the ' this part with your own Dataset

Dim DT as DataTable
Dim Dr as DataRow
Dim I as Integer

' Create a DataTable
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))

' Make some rows and put some sample data in
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
' Add the row to the DataTable
Dt. Rows.Add (DR)
Next

Return DT

End Function

</script>

<title>datarepeater Paging example</title>
<style type=text/css>

Body {
font:10px Verdana, Arial, Helvetica, "sans serif"; COLOR: #000000;
}
txt
font-size:12px
}
</style>
<body>
<form name=form1 method=post runat= "Server" >
<table class=txt width= "100%" border=0>
<tbody><tr><td>

<asp:hyperlink id=lnkprev runat= "Server" ><< prev</asp:hyperlink>
<asp:hyperlink id=lnknext runat= "Server" >next >></asp:HyperLink>
<asp:label id=lblcurrentpage runat= "Server" ></asp:Label>
of <asp:label id=lbltotalpage runat= "Server" ></asp:Label>

</td></tr></tbody></table>
<asp:repeater id=repeater1 runat= "Server" >


<ItemTemplate>
<table class=txt width= "100%" border= "0" >
<tr>
<td>
Order Date: <%# DataBinder.Eval (Container.DataItem, "Datetimevalue", "{0:d}")%>
</td><tr><td>
Quantity: <%# DataBinder.Eval (Container.DataItem, "IntegerValue", "{0:n2}")%>
</td><tr><td>
Item: <%# DataBinder.Eval (Container.DataItem, "StringValue")%>
</td><tr><td>
Order Date: <asp:checkbox id=chk1 checked= ' <%# databinder.eval (Container.DataItem, "Boolvalue")%> ' runat= ' Server "/>
</td></tr></table>
</ItemTemplate>

</asp:repeater>
&LT;HR hight= "1" >

<p>datasource:microsoft QuickStart Example

Http://cht.gotdotnet.com/quickstart/aspplus/doc/webdatabinding.aspx
</p>
<p>reference:msdn. NET Framework Class Library

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/ Frlrfsystemwebuiwebcontrolspageddatasourceclasstopic.asp
</p><p>
Paging with Repeater control in asp.net

Http://www.charon.co.uk/content.aspx?CategoryID=28&ArticleID=21 </p></form></body>

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.