Private Sub dg1_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dg1.ItemCreated
Try
If e.Item.ItemType = ListItemType.Pager Then
Dim pager As TableCell = e.Item.Cells(0)
' Next>> Last>>
AddLinkNextPage(pager)
AddLinkLastPage(pager)
'<<First <<Prev
AddLinkPrevPage(pager)
AddLinkFirstPage(pager)
End If
Catch ex As Exception
System.Diagnostics.Trace.WriteLine(ex.ToString)
End Try
End Sub
Private Sub AddLinkFirstPage(ByVal pager As TableCell)
Try
If TypeOf (pager.Controls(0)) Is LinkButton Then
Dim btnFirst As LinkButton = New LinkButton
btnFirst.Font.Name = "Tahoma"
btnFirst.Font.Size = pager.Font.Size.Smaller
btnFirst.ForeColor = dg1.PagerStyle.ForeColor
btnFirst.Text = "<< First "
AddHandler btnFirst.Click, AddressOf GoToFirstPage
pager.Controls.AddAt(0, btnFirst)
Else
Dim btnFirst As Label = New Label
btnFirst.Font.Name = "Tahoma"
btnFirst.Font.Size = pager.Font.Size.Smaller
btnFirst.ForeColor = dg1.PagerStyle.ForeColor
btnFirst.Text = ""
pager.Controls.AddAt(0, btnFirst)
End If
Catch ex As Exception
System.Diagnostics.Trace.WriteLine(ex.ToString)
End Try
End Sub
Private Sub AddLinkPrevPage(ByVal pager As TableCell)
Try
If TypeOf (pager.Controls(0)) Is LinkButton Then
Dim btnPrev As LinkButton = New LinkButton
btnPrev.Font.Name = "Tahoma"
btnPrev.Font.Size = pager.Font.Size.Smaller
btnPrev.ForeColor = dg1.PagerStyle.ForeColor
btnPrev.Text = "<< Prev "
AddHandler btnPrev.Click, AddressOf GoToPrevPage
pager.Controls.AddAt(0, btnPrev)
Else
Dim btnPrev As Label = New Label
btnPrev.Font.Name = "Tahoma"
btnPrev.Font.Size = pager.Font.Size.Smaller
btnPrev.ForeColor = dg1.PagerStyle.ForeColor
btnPrev.Text = ""
pager.Controls.AddAt(0, btnPrev)
End If
Catch ex As Exception
System.Diagnostics.Trace.WriteLine(ex.ToString)
End Try
End Sub
Private Sub AddLinkNextPage(ByVal pager As TableCell)
Try
Dim ccount As Integer = pager.Controls.Count
If TypeOf (pager.Controls(pager.Controls.Count - 1)) Is LinkButton Then
Dim btnNext As LinkButton = New LinkButton
btnNext.Font.Name = "Tahoma"
btnNext.Font.Size = pager.Font.Size.Smaller
btnNext.ForeColor = dg1.PagerStyle.ForeColor
btnNext.Text = " Next >>"
AddHandler btnNext.Click, AddressOf GoToNextPage
pager.Controls.AddAt(ccount, btnNext)
Else
Dim btnNext As Label = New Label
btnNext.Font.Name = "Tahoma"
btnNext.Font.Size = pager.Font.Size.Smaller
btnNext.ForeColor = dg1.PagerStyle.ForeColor
btnNext.Text = ""
pager.Controls.AddAt(ccount, btnNext)
End If
Catch ex As Exception
System.Diagnostics.Trace.WriteLine(ex.ToString)
End Try
End Sub
Private Sub AddLinkLastPage(ByVal pager As TableCell)
Try
Dim ccount As Integer = pager.Controls.Count
If TypeOf (pager.Controls(pager.Controls.Count - 1)) Is LinkButton Then
Dim btnLast As LinkButton = New LinkButton
btnLast.Font.Name = "Tahoma"
btnLast.Font.Size = pager.Font.Size.Smaller
btnLast.ForeColor = dg1.PagerStyle.ForeColor
btnLast.Text = " Last >>"
AddHandler btnLast.Click, AddressOf GoToLastPage
pager.Controls.AddAt(ccount, btnLast)
Else
Dim btnLast As Label = New Label
btnLast.Font.Name = "Tahoma"
btnLast.Font.Size = pager.Font.Size.Smaller
btnLast.ForeColor = dg1.PagerStyle.ForeColor
btnLast.Text = ""
pager.Controls.AddAt(ccount, btnLast)
End If
Catch ex As Exception
System.Diagnostics.Trace.WriteLine(ex.ToString)
End Try
End Sub
Private Sub GoToFirstPage(ByVal sender As Object, ByVal e As EventArgs)
dg1.CurrentPageIndex = 0
dg1.DataBind()
End Sub
Private Sub GoToPrevPage(ByVal sender As Object, ByVal e As EventArgs)
If dg1.CurrentPageIndex - 1 > 0 Then
dg1.CurrentPageIndex -= 1
Else
dg1.CurrentPageIndex = 0
End If
dg1.DataBind()
End Sub
Private Sub GoToNextPage(ByVal sender As Object, ByVal e As EventArgs)
If dg1.CurrentPageIndex + 1 < dg1.PageCount - 1 Then
dg1.CurrentPageIndex += 1
Else
dg1.CurrentPageIndex = dg1.PageCount - 1
End If
dg1.DataBind()
End Sub
Private Sub GoToLastPage(ByVal sender As Object, ByVal e As EventArgs)
dg1.CurrentPageIndex = dg1.PageCount - 1
dg1.DataBind()
End Sub