PageIndexChanged Not Firing

A

ajamrozek

I've read a number of threads covering this topic and have finally hit
a spot that I can't find any topics on.
The general problem of the PageIndexChanged not firing has been covered
but my situation is a little different. Here goes:
My aspx page has a listbox that tells the datagrid what columns to
display, and some textboxes and dropdownlists to tell the datagrid what
filter to apply. Any of these can be changed at any time and clicking
a button applies these attributes to the datagrid. So the datagrid has
AutoGenerateColumns = False and builds the columns whenever prompted.
I'm handling the grid binding in a sub that accepts some params to get
the data from the http cache and to keep the columns that it already
has. It has AllowSort = True and AllowPaging = True. I am using the
default paging and sorting.
All works well until I attempt page to the very last page. Meaning the
pager displays 1 - 25 then shows the lipsis for the next set of pages.
I can go to the next set of pages and navigate the 26 - 50 pages here
successfully (with a little hack to accept the new base being 25
instead of 0). However when I go the lipsis to see pages 51 - 75, the
PageIndexChanged event does not execute.
Help!
Here's some of the code involved.

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

InitializeComponent()

oDataGrid = Me.FindControl("dgAPL")

If Not Page.IsPostBack Then

'the datagrid is bound every time the page initializes, but only if
it's not a
'postback does it fully Bind. meaning the database is hit for the data
and the
'columns are generated

DataBindGrid()

Session("IT_Filter") = Nothing
Session("IT_Sort") = Nothing
Session("IT_FilterVisible") = Nothing

DataBindDisplayFields()

DataBindFilterControls()

Else

'if it is a postback then the database is not hit for the data and if
the
'session variable for the columns hasn't changed, then the columns are
not
're-gen'd

DataBindGrid(True, True)

End If


End Sub

Private Sub DataBindGrid(Optional ByVal blGetFromCache As Boolean =
False, Optional ByVal blKeepColumns As Boolean = False)

Dim dv As DataView = New DataView

With oDataGrid

If blGetFromCache AndAlso Not
HttpContext.Current.Cache.Item("IT_APL") Is Nothing Then
dv =
QwestProcurementAPL.DataAccess.SQLDataSet("IT_APL", "dbo.IT_APL_GET",
True).Tables(0).DefaultView
Else
dv =
QwestProcurementAPL.DataAccess.SQLDataSet("IT_APL", "dbo.IT_APL_GET",
False).Tables(0).DefaultView
End If


Dim i As Integer, colColumns As New Collection, colTemplate
As BoundColumn

For i = 0 To .Columns.Count - 1

Try

.Columns.RemoveAt(i)
i -= 1

Catch ex As Exception

End Try

Next

If blKeepColumns And Not Session("IT_APLDataGridColumns")
Is Nothing Then

For i = 1 To CType(Session("IT_APLDataGridColumns"),
Collection).Count

.Columns.Add(Session("IT_APLDataGridColumns")(i))

Next

Else

For i = 0 To dv.Table.Columns.Count - 1

colTemplate = New BoundColumn

With colTemplate
.HeaderText = dv.Table.Columns(i).ColumnName
.SortExpression =
dv.Table.Columns(i).ColumnName
.DataField = dv.Table.Columns(i).ColumnName
End With

.Columns.Add(colTemplate)

colColumns.Add(colTemplate)

Session("IT_APLDataGridColumns") = colColumns

Next

End If

If Not Session("IT_Filter") = Nothing Then
dv.RowFilter = Session("IT_Filter")
Else
dv.RowFilter = Nothing
End If

If Not Session("IT_Sort") = Nothing Then
dv.Sort = Session("IT_Sort")
Else
dv.Sort = Nothing

End If
.DataSource = dv

.DataBind()

Try
.CurrentPageIndex = Session("IT_PageIndex")

Catch ex As Exception

End Try


End With

blDatagridBound = True

End Sub

Public Sub Grid_Change(ByVal sender As Object, ByVal e As
DataGridPageChangedEventArgs) Handles oDataGrid.PageIndexChanged

'index is always based on 0 to whatever the max page count is. in this
case, 25
'so i had to catch this and set the index accordingly if the calling
page is
'greater than or equal to 25

Dim intIndex As Integer = e.NewPageIndex

If oDataGrid.CurrentPageIndex >= 25 Then
intIndex += 24

End If

Session("IT_PageIndex") = intIndex
DataBindGrid(True, True)
blIndexChanged = True

End Sub
 
A

ajamrozek

I think I may have this solved. I called the .DataBind Method of my
DataGrid (oDataGrid) right at the end of my Page_Load event. Now my
pager works beautifully.
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top