PC Review


Reply
Thread Tools Rate Thread

Customize datagrid pager

 
 
=?Utf-8?B?UmF5?=
Guest
Posts: n/a
 
      7th Aug 2005
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid Pager customization James T. Microsoft ASP .NET 0 22nd Mar 2005 02:08 PM
DataGrid pager James T. Microsoft ASP .NET 0 14th Mar 2005 02:51 PM
DataGrid Pager Dave Microsoft ASP .NET 0 5th Oct 2004 08:24 AM
Datagrid & pager Ben Microsoft ASP .NET 2 16th Jul 2004 04:16 AM
pager in datagrid kgs Microsoft ASP .NET 1 27th Nov 2003 12:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:01 AM.