This is what I use. It's something I came up with myself.
.aspx
Code:
<asp:Repeater id="rep_message_list" OnItemDataBound="rep_message_list_onitemdatabound" runat="server">
<itemtemplate>
<tr valign="middle" title="View Message: <%#Eval("notice_title")%>" onmouseover="this.style.background='#F7C464'" onmouseout="this.style.background=''" style="height:15px;cursor: pointer;" onclick="window.location='messages_view.aspx?noticeref=<%#Eval("noticeref")%>'">
<td valign="middle" class="client_data_box" style="width:35%;"><asp:HyperLink ID="hyp_sentby" runat="server" cssclass="dblue8" text='<%#Eval(HttpUtility.HtmlEncode("sentby_user"))%>' /></td>
<td valign="middle" class="client_data_box" style="width:35%;"><asp:HyperLink ID="hyp_title" runat="server" cssclass="dblue8" text='<%#Eval(HttpUtility.HtmlEncode("notice_title"))%>' /></td>
<td valign="middle" class="client_data_box" style="width:10%;"><asp:HyperLink ID="hyp_dateadded" runat="server" cssclass="dblue8" text='<%#format(Eval(HttpUtility.HtmlEncode("dateadded")),"dd/MM/yyyy")%>' /></td>
<td valign="middle" class="client_data_box" style="width:20%;"><asp:HyperLink ID="hyp_read" runat="server" cssclass="dblue8" /></td>
</tr>
</itemtemplate>
</asp:Repeater>
<table id="frm_buttons" style="width:100%;" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="width:50%;padding-left:5px;" align="left">
<asp:ImageButton ID="frm_previous" runat="server" imageurl="form_previous_fade1.gif" ToolTip="No previous pages" Enabled="false" OnClick="but_previous" OnClientClick="window.location='#top'" />
<asp:ImageButton ID="frm_first" runat="server" imageurl="form_first1.gif" ToolTip="Back to first page" visible="false" OnClick="but_first" OnClientClick="window.location='#top'" />
</td>
<td style="width:50%;padding-right:5px;" align="right">
<asp:ImageButton ID="frm_next" runat="server" imageurl="form_next1.gif" ToolTip="Next 15 Messages" OnClick="but_next" OnClientClick="window.location='#top'" />
</td>
</tr>
</table>
.aspx.vb
Code:
Private _cur_record As Integer
Sub Page_Load
message_list_initial()
set_buttons()
End Sub
Sub message_list_initial()
'This function sets up the initial list that is viewed when the page is first loaded
Dim conn As New MySqlConnection(connString)
Dim mycommand as New MySqlCommand("SELECT field1,field2,field3 FROM tbl",conn)
Dim rs As MySqlDataReader
_cur_record = 0
Try
conn.Open()
rs = mycommand.ExecuteReader
rep_message_list.DataSource = rs
rep_message_list.DataBind()
rs.Close()
Catch ex As Exception
'Whatever exception dealing you want
Finally
mycommand.Dispose()
conn.Close()
conn.Dispose()
End Try
End Sub
Sub but_previous(ByVal s As Object, ByVal e As ImageClickEventArgs)
_cur_record -= 15 'I have a ddl that allows you to select how many records per page that you could put in here ddl_no_messages.SelectedValue
if _cur_record <0 Then _cur_record = 0
set_buttons()
message_list_update()
End Sub
Sub but_next(ByVal s As Object, ByVal e As ImageClickEventArgs)
_cur_record += 15 'I have a ddl that allows you to select how many records per page that you could put in here ddl_no_messages.SelectedValue
set_buttons()
message_list_update()
End Sub
Sub but_first(ByVal s As Object, ByVal e As ImageClickEventArgs)
_cur_record = 0
set_buttons()
message_list_update()
End Sub
Sub set_buttons()
If _cur_record > 1 Then
frm_previous.Enabled = True
frm_previous.ImageUrl = "form_previous1.gif"
frm_previous.ToolTip = "Previous " & ddl_message_list_no.SelectedValue & " Messages"
Else
frm_previous.Enabled = False
frm_previous.ImageUrl = "form_previous_fade1.gif"
frm_previous.ToolTip = "No previous pages"
End If
If _cur_record >= (ddl_message_list_no.SelectedValue + 1) Then
frm_first.Visible = True
Else
frm_first.Visible = False
End If
If (no_messages - ddl_message_list_no.SelectedValue) > _cur_record Then
frm_next.Enabled = True
frm_next.ImageUrl = "form_next1.gif"
frm_next.ToolTip = "Next " & ddl_message_list_no.SelectedValue & " Messages"
Else
frm_next.Enabled = False
frm_next.ImageUrl = "form_next_fade1.gif"
frm_next.ToolTip = "No more pages"
End If
End Sub
Sub message_list_update()
Dim conn As New MySqlConnection(connString)
Dim mycommand As New MySqlCommand
Dim rs As MySqlDataReader
mycommand.Connection = conn
'You could substitute 15 in the SQL for the ddl_no_messages.SelectedValue
Dim strsql As String = "SELECT field1,field2,field3 FROM tbl LIMIT " & _cur_record & ",15;"
Try
conn.Open()
mycommand.CommandText = strsql
rs = mycommand.ExecuteReader()
rep_message_list.DataSource = rs
rep_message_list.DataBind()
rs.Close()
Catch ex As Exception
'Whatever exception dealing you want
Finally
mycommand.Dispose()
conn.Close()
conn.Dispose()
End Try
End Sub
Private ReadOnly Property no_messages() As Integer
Get
Dim conn As New MySqlConnection(connString)
Dim strsql As String = "SELECT COUNT(field1) AS no_records FROM tbl"
Dim mycommand As New MySqlCommand
mycommand.Connection = conn
Dim rs As MySqlDataReader
Try
conn.Open()
mycommand.CommandText = strsql
rs = mycommand.ExecuteReader()
If rs.HasRows Then
rs.Read()
Return rs("no_records")
Else
Return 0
End If
rs.Close()
Catch ex As Exception
'Whatever exception dealing you want
Return 0
Finally
mycommand.Dispose()
conn.Close()
conn.Dispose()
End Try
End Get
End Property
So, basically, I have a sub to deal with each button; previous, next and first. A sub to build the initial list of items. A property to count the total items in the list, a sub to deal with which buttons need to be enabled, showing etc. and a sub to deal with updating the list based on what the current record to start at is.
Hope that helps...