Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • 2 weeks later...
Posted

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

Posted

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

 

Can you post a bit more code?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...