Datagrid Paging Problem

sj1187534

Centurion
Joined
Jun 10, 2003
Messages
108
Location
Dallas, Houston, etc.etc.
Hi...I am having a problem with datafrid paging...Here's the code that i am using :

Private Sub dgrFree_PageIndexChanged(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgrFree.PageIndexChanged
Me.dgrFree.CurrentPageIndex = e.NewPageIndex
BindData(GetDataByCategory("free"))
End Sub

Private Function GetDataByCategory(ByVal cat As String) As DataSet
Dim ds As DataSet
Dim catb As New B
ds = catb.SearchByCategory(cat)
Return ds
End Function

Private Function BindData(ByVal ds As DataSet)
If Not ds Is Nothing Then
Me.dgrFree.DataSource = ds.Tables(2).DefaultView
Me.dgrFree.DataBind()
Else
Me.dgrFree.DataSource = Nothing
Me.dgrFree.DataBind()
End If
End Function

The index of the page is changing but it shows the first page all the time. I think there is some problem in re-loading the datagrid.

Thanks
SJ
 
I am testing for the IsPostBack condition and the enableviewstate is enabled too. I just dont get it!!! The same concept is working on one page but not on the other!!!!! One thing I observed is, on the page that it is not working, I am using ItemDataBound on the datagrid. As you might have guessed, I am not using the ItemDataBound on the page it is working. Does that make any difference by any chance?

SJ
 
Hi..thanks for the reply. I actually figured out what was wrong. The paging code was fine but there was a small logic error in the ItemDataBound subroutine for the datagrid. I was not changing the itemindex based on the pageindex of the datagrid.

I was using:

Private Sub dgrFree_ItemDataBound(...)
..
Dim dr As DataRow = Me.dgrFree.DataSource.Table.Rows(e.Item.ItemIndex)
...
End Sub

instead of :

Private Sub dgrFree_ItemDataBound(...)
..
Dim dr As DataRow = Me.dgrFree.DataSource.Table.Rows(Me.dgrFree.CurrentPageIndex * Me.dgrFree.PageSize + e.Item.ItemIndex)
...
End Sub

The CurrentPageIndex was chaging fine but the item index were still starting from '0'. So, the same results are showing up on each page.

SJ

Robby said:
Can you post a bit more code?
 
Back
Top