Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

Sponsored Links

Discuss "Paging" in the .Net Development forum.

.Net Development - Learn about the Microsoft.Net framework and how to create powerful web-based (ASP.net) and client-based (Windows Forms) applications utilizing various languages such as C#, VB.Net, J# and others.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1  
Old July 7th, 2008, 04:17 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default Paging

I'm using a Repeater control, is there a control for paging or will this be done
manually, if it must be done manually, where the best paging script?

Shem
Reply With Quote
Sponsored Links
  #2  
Old July 7th, 2008, 04:44 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

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...
Reply With Quote
The Following User Says Thank You to richyrich For This Useful Post:
Shem (July 7th, 2008)
Reply

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -4. The time now is 07:02 PM.



Content Relevant URLs by vBSEO 3.2.0