Mike,
I did this over a year ago although I'm not sure if it's simple or not. But
I'll give it a try.
Here my repeater control:
<asp:Repeater id="rptContributionList" runat="server">
<HeaderTemplate>
<table border="1">
</HeaderTemplate>
<ItemTemplate>
<tr bgcolor="#ffffff">
<td>
<%# Container.DataItem("Date_Received") %>
</td>
<td>
<%# Container.DataItem("Amount_Requested") %>
</td>
<td>
<%# Container.DataItem("Amount_Paid") %>
</td>
<td>
<%# Container.DataItem("Date_Issued") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:Label ID="lblNavigation" Runat="server"></asp:Label>
Here is my code that binds the data to the repeater control:
Public Sub LoadPagedContributionList(ByVal strPageNumber as String, ByVal
strNumOfRecsPerPage as String, ByVal rptRepeaterControl as Repeater)
Dim objConn As SqlConnection
Dim objSQLCommand As SqlCommand
Dim objDataReader As SqlDataReader
Dim objParam As SqlParameter
'Set up our connection object and SQL command object.
objConn = New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
objSQLCommand = New SqlCommand("CCT_s_GetAllContributionsPaged", objConn)
'Set the stored procedure.
objSQLCommand.CommandType = CommandType.StoredProcedure
'Add parameters...
objParam = objSQLCommand.Parameters.Add("@Page_Number", strPageNumber)
objParam = objSQLCommand.Parameters.Add("@Records_Per_Page",
strNumOfRecsPerPage)
'Open the db connection.
objConn.Open()
'Execute the procedure.
objDataReader = objSQLCommand.ExecuteReader()
'Now bind the data to the dropdownlist.
rtpRepeater.DataSource = objDataReader
rtpRepeater.DataBind()
'Close the DB connection.
objConn.Close()
objDataReader.Close()
End Sub
Don't forget your imports needed to hit the sql server database:
Imports System.Data
Imports System.Data.SqlClient
You'll notice that I pass in 2 values, Page_Number and Records_Per_Page. You
can hard-code the value for Records_Per_Page in the page
or in your stored procedure. I just wanted this to be a little more flexible.
Anyhow, let's move on to the code that is called when the page loads:
Dim strPageNumber As String = Request.QueryString("PageNum")
'Check the page number...
If strPageNumber = "" Then
'No page number (ID) present. Set it to one to indicate page 1.
strPageNumber = "1"
End If
'Get any value for number of recs per page into a variable.
Dim strNumOfRecsPerPage As String = Request.QueryString("RecsPerPage")
Here is where I make the call to the above database code to bind the data to
the control:
LoadPagedContributionList(strPageNumber, strNumOfRecsPerPage,
rptRepeaterControl)
And here is the call to load the links to get to page 1, 2, 3, etc.
'Call sub that loads the paging links at the bottom of the page.
DisplayPagingLinks(strNumOfRecsPerPage, strPageNumber)
Private Sub DisplayPagingLinks(ByVal strNumOfRecsPerPage As String, ByVal
strPageNumber As String)
'Call a method that returns the ttl record count.
Dim intTotalRecordCount As Integer = GetTotalNumberOfContributionRequests()
'Now let's get the max number of pages that we can have.
Dim intMaxNumberOfPages As Integer = (intTotalRecordCount / strNumOfRecsPerPage)
If intMaxNumberOfPages Mod strNumOfRecsPerPage <> 0 Then
intMaxNumberOfPages += 1
End If
'Now loop and set the links to the label used for paging.
Dim intLoopCounter As Integer
For intLoopCounter = 1 To intMaxNumberOfPages - 1
lblNavigation.Text += (" <a href=""ContributionList.aspx?PageID=" &
intLoopCounter & "&RecsPerPage=" & strNumOfRecsPerPage & """>" & intLoopCounter
& "</a> ")
Next
End Sub
I hope you can make your way through the code. There's so much within the page
that I did that is was nearly impossible to send the whole thing. But if you
really need a full example, I can take the code and put it into it's own VS.NET
project and send it to you.]
Mark
Mike Belcher <[EMAIL PROTECTED]> wrote:
Anyone have or know of an simple example of paging records with a repeater
control?
mike
Yahoo! Groups SponsorADVERTISEMENT
---------------------------------
Yahoo! Groups Links
To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
[Non-text portions of this message have been removed]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/