Datagrid Paging Broke?

C

Chris

I've got a datagrid on my ASP.Net page with paging enabled that allows
users to update data. If users are on, let's say, page 9 and update a
row it ALWAYS kicks them back to page 2 while I'd prefer it to stay on
page 9.

Here's my code:

Private Sub dgInventory_PageIndexChanged(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
Handles dgInventory.PageIndexChanged
dgInventory.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub
----------------------------------------------------------------------------
Private Function BindGrid()
Dim objAsset As New AssetMgmtData
Dim dsDataset As New DataSet

Try
dsDataset =
objAsset.PreRecByCostCenter(cboCostCenter.SelectedItem.Text.ToString())

dgInventory.DataSource = dsDataset
dgInventory.DataBind()

Catch ex As Exception
Response.Write(ex.Message)
Finally
objAsset = Nothing
dsDataset = Nothing
End Try
End Function
 
A

ashelley

I've got a datagrid on my ASP.Net page with paging enabled that allows
users to update data. If users are on, let's say, page 9 and update a
row it ALWAYS kicks them back to page 2 while I'd prefer it to stay on
page 9.

Here's my code:

Private Sub dgInventory_PageIndexChanged(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
Handles dgInventory.PageIndexChanged
dgInventory.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub
----------------------------------------------------------------------------
Private Function BindGrid()
Dim objAsset As New AssetMgmtData
Dim dsDataset As New DataSet

Try
dsDataset =
objAsset.PreRecByCostCenter(cboCostCenter.SelectedItem.Text.ToString())

dgInventory.DataSource = dsDataset
dgInventory.DataBind()

Catch ex As Exception
Response.Write(ex.Message)
Finally
objAsset = Nothing
dsDataset = Nothing
End Try
End Function

store the current page in a viewstate variable and set the current
page index right before databind. If the page doesn't exist during
databind, it will exception. You will need logic in your program to
effectively report this situation or correct it by reseting the page
index to a page that _will_ exist and rebind.

-Adam
 

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,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top