sj1187534 Posted April 15, 2004 Posted April 15, 2004 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 Quote
Moderators Robby Posted April 15, 2004 Moderators Posted April 15, 2004 Are you re-loading the data in your Page Load event each time, if so ... use IsPostBack to test for postback . Quote Visit...Bassic Software
sj1187534 Posted April 24, 2004 Author Posted April 24, 2004 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 Quote
Moderators Robby Posted April 24, 2004 Moderators Posted April 24, 2004 Can you post a bit more code? Quote Visit...Bassic Software
sj1187534 Posted April 26, 2004 Author Posted April 26, 2004 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? Quote
Moderators Robby Posted April 26, 2004 Moderators Posted April 26, 2004 Good stuff, glad you found it. Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.