DataPager. Could someone, please, help me finishing this?


S

shapper

Hello,

I am creating a DataPager TemplatePagerField at runtime and trying to
replicate the following paging:

http://www.frequency-decoder.com/demo/table-sort-revisited/paginate/

At the moment this is not working very well. A postback is made every
time I click a button or a number.

I think it is my calculation on my TemplatePagerField PagerCommand
event.

Could someone help me out?

Thank You,

Miguel

Here is my code:


PagerCommand event handler

Private Sub tpftags_PagerCommand(ByVal sender As Object, ByVal e
As DataPagerCommandEventArgs)

' Check which button raised the event
Select Case e.CommandName

Case "Next"
Dim newIndex As Integer = e.Item.Pager.StartRowIndex +
e.Item.Pager.PageSize
If newIndex <= e.TotalRowCount Then
e.NewStartRowIndex = newIndex
e.NewMaximumRows = e.Item.Pager.MaximumRows
End If

Case "Previous"
Dim newIndex As Integer = e.Item.Pager.StartRowIndex +
e.Item.Pager.PageSize
If newIndex >= e.TotalRowCount Then
e.NewStartRowIndex = e.Item.Pager.StartRowIndex -
e.Item.Pager.PageSize
e.NewMaximumRows = e.Item.Pager.MaximumRows
End If

Case "First"
e.NewStartRowIndex = 0
e.NewMaximumRows = e.Item.Pager.MaximumRows

Case "Last"
e.NewStartRowIndex = e.Item.Pager.MaximumRows -
e.Item.Pager.PageSize
e.NewMaximumRows = e.Item.Pager.MaximumRows

Case "Number"
e.NewStartRowIndex = Convert.ToInt32(e.CommandArgument)
e.NewMaximumRows = e.Item.Pager.MaximumRows

End Select

End Sub

Class that implements ITemplate:

Public Class PagerTemplate
Implements ITemplate

Public Sub InstantiateIn(ByVal container As Control) Implements
ITemplate.InstantiateIn

Dim lbfirst As New LinkButton
lbfirst.Text = "«"
lbfirst.CommandName = "First"
container.controls.add(lbfirst)

Dim lbprevious As New LinkButton
lbprevious.Text = "<"
lbprevious.CommandName = "Previous"
container.controls.add(lbprevious)

Dim cont As DataPagerFieldItem = CType(container,
DataPagerFieldItem)
Dim a As DataPager = CType(cont.NamingContainer, DataPager)

Dim currentPage As Integer = (a.StartRowIndex / a.PageSize) + 1
Dim totalPages As Integer = a.TotalRowCount / a.PageSize

For i = currentPage To totalPages

Dim lbnumber As New LinkButton
lbnumber.Text = i.ToString
lbnumber.CommandArgument = i.ToString
lbnumber.CommandName = "Number"
container.controls.Add(lnnumber)

Next i

Dim lbnext As New LinkButton
lbnext.Text = ">"
lbnext.CommandName = "Next"
container.Controls.Add(lbnext)

Dim lblast As New LinkButton
lblast.Text = "»"
lblast.CommandName = "Last"
container.Controls.Add(lblast)

End Sub ' InstantiateIn

#End Region ' Implementation

#Region "Controls Events"

#End Region ' Controls Events

End Class ' PagerTemplate
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top