Customize datagrid pager

G

Guest

I am trying to add a "Next >" and "<Prev" button to the pager of my datagrid.
I have been able to add the hyperlinks to the pager. I am now trying to
determine the correct postback script to emulate so that these hyperlinks
force the postback of the appropriate linkbuttons in the pager.

Let's take a pager with pager: 1 2 3 4 5
It consists of: linkbutton linkbutton label linkbutton linkbutton

I want it to be: < Prev 1 2 3 4 5 Next >
It consists of: hyperlink linkbutton linkbutton label linkbutton linkbutton
hyperlink

If I am on page 3 then by clicking on Next, I want the postback for
linkbutton 4 to be posted.

Currently my script is enumerating throught the controls of the pager to
determine which is the label control. The label is the current active page
as the other pages are linkbutton controls in the collection. My code is as
follows:

Private Sub dgSearch_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgSearch.ItemCreated
If e.Item.ItemType = ListItemType.Pager Then
Try
Dim Pager As TableCell = CType(e.Item.Controls(0), TableCell)
Dim x As Int16 = 0

Dim myEnumerator As IEnumerator =
Pager.Controls.GetEnumerator()
While (myEnumerator.MoveNext())
Dim myObject As Object = myEnumerator.Current
If (myObject.GetType().Equals(GetType(Label))) Then
If Not x = 0 Then
Exit While
End If
End If
x += 1
End While

'Additional Pager Text
Dim InfoText As Label = New Label
InfoText.ID = "it"
InfoText.Font.Bold = True
InfoText.Text = "Page: "
Pager.Controls.AddAt(0, InfoText)

'Add custom Previous/Next paging section
'Loop indexed by 2 through datagrid paging numbers controls
jumping over the spaces
Dim i As Integer = 1
Dim endPagingIndex As Integer = (Pager.Controls.Count - 1)

Do While (i <= Pager.Controls.Count)
Dim pgNumbers As Object = Pager.Controls(i)
If (pgNumbers.GetType.Name = "Label") Then
'Dim lb As Label = CType(pgNumbers, Label)
'Find index position of paging ellipses
If (i > 1) And (i < endPagingIndex) Then
'Insert Previous & Next page link
i += 1
endPagingIndex += 1

Dim Prev As HyperLink = New HyperLink
Prev.ID = "pre"
Prev.Text = "< Prev "
prev.NavigateUrl = "javascript:__doPostBack('" &
dgSearch.UniqueID & "$_ctl14$_ctl" & (x / 2) - 1 & "','')"
Pager.Controls.AddAt(1, Prev)

Dim Nex As HyperLink = New HyperLink
Nex.ID = "nex"
Nex.Text = " Next >"
Nex.NavigateUrl = "javascript:__doPostBack('" &
dgSearch.UniqueID & "$_ctl14$_ctl" & (x / 2) + 1 & "','')" '" &
CInt((endPagingIndex - 1) / 2) & "
Pager.Controls.AddAt(endPagingIndex + 1, Nex)
ElseIf (i > 1) And (i = endPagingIndex) Then
'Insert Previous page link
i += 1
endPagingIndex += 1

Dim Prev As HyperLink = New HyperLink
Prev.ID = "pre"
Prev.Text = "< Prev "
prev.NavigateUrl = "javascript:__doPostBack('" &
dgSearch.UniqueID & "$_ctl14$_ctl" & (x / 2) - 1 & "','')"
Pager.Controls.AddAt(1, Prev)
ElseIf (i = 1) And (i < endPagingIndex) Then
'Insert Next page link
i += 1
endPagingIndex += 1

Dim Nex As HyperLink = New HyperLink
Nex.ID = "nex"
Nex.Text = " Next >"
Nex.NavigateUrl = "javascript:__doPostBack('" &
sender.UniqueID & "$_ctl14$_ctl" & 1 & "','')"
Pager.Controls.AddAt(endPagingIndex, Nex)
End If
End If
i += 1
Loop
Catch ex As Exception

End Try
End If

I am having difficulty to build the NavigateUrl for the hyperlink control.
I have determined that the postback of the linkbuttons in the pager is a
hierarchy of UniqueIDs seperated by $. I.e. dgSearch$_ctl14$_ctl4

So it consists of: the datagrid name $ a control that I don't know (_ctl14)
$ the id of the linkbutton.

My question is, what is the name of the control that I am missing (_ctl14)
or is there another way to get this to work?

This is my first try to customize the pager and there is no article out
there that describes this scenario.
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top