Datagrid paging trouble: correct view, incorrect id
Hi to all,
I've a big headache figuring out wat's happening lately on my
paging methods...
In a few words, I'll give an example:
I've a datagrid which contains , let's say, 200 records.
They're splitted up 10 per page, so what we'll have will be 20 pages..assuming:
Pagesize = 10
PageButtonCOunt = 10
BUT, and here comes the pain, when i click on the three dots:
" 1 2 3 4 5 6 7 8 9 10 ... " <- here
The page repost itself and I view correctly
" ... 11 12 13 14 15 16 17 18 19 20
but if i rollover the mouse on a page number the link is, ie, for 11:
javascript:__doPostBack('FindGrafici2$dgTimeSales$_ctl79$_ctl1','')
sending me to page "2" !!
Sounds like it can't maintain the state of the pager, but all seems
"viewstated" (^_^) properly...
What' the deal?? Anyone has a clue for this one?
Any help would be VERY, VERY appreciated...
tnx to all
You should actually have viewtstate disabled, viewstate can get very messy for large data grids, and it is not needed for pageing. I actually hate the built in pageing, and would reccomend doing the pageing by hand because it will give you more control (I also do not use data grids because I like more control, I use repeaters).
Originally posted by PeOfEo You should actually have viewtstate disabled,
That's the strange thing, actually it is all enabled.. so there is something else that is not working... sigh!
Originally posted by PeOfEo viewstate can get very messy for large data grids, and it is not needed for pageing. I actually hate the built in pageing, and would reccomend doing the pageing by hand because it will give you more control (I also do not use data grids because I like more control, I use repeaters).
Yeah, i understand. Unfortunately I have to use a Datagrid control... if i don't reach a solution soon, I'll go for a custom paging.
Any other idea?
I use datagrids extensively, and have never run into this problem before. How are you binding the data and how are you handling the DataGrid1_PageIndexChanged method?
Robert M. Teague
Senior Programmer/Analyst
Kamehameha Schools
http://www.ksbe.edu
Sub Page_Load(Src As Object, E As EventArgs)
If Not Page.IsPostBack then
BindData()
End If
end sub
Sub BindData()
Dim DBConn as OleDbConnection
DBConn = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath("/news.mdb;"))
Dim strSQL As String
strSQL = "Select id, posts from tblposts order by id desc"
Dim AdapterDockets As OleDbDataAdapter
Dim DataSetDockets As DataSet
AdapterDockets = New OleDbDataAdapter(strSQL, dbconn)
DataSetDockets = New DataSet()
AdapterDockets.Fill(DataSetDockets)
myDataGrid.DataSource = DataSetDockets
myDataGrid.DataBind()
End Sub
Sub myDataGrid_PageChanger(ByVal Source As Object, ByVal E As DataGridPageChangedEventArgs)
myDataGrid.CurrentPageIndex = E.NewPageIndex
BindData()
end sub
thats some pageing code of mine for a news column that happens to be access driven. Maybe that will help you. Look how I have the if not ispostback and the data binding setup.
I think I see your problem. I think I have run into some similar to this in the past now that I think about it.
Try changing your bind sub like this:
Private Sub BindData()
Try
dgTimeSales.DataSource = MyDataSource
dgTimeSales.DataBind()
Catch ex As Exception
If dgTimeSales.CurrentPageIndex - 1 >= 0 Then
dgTimeSales.CurrentPageIndex = dgTimeSales.CurrentPageIndex - 1
BindData
End If
End Try
End Sub
This way if the page index isn't valid, for whatever reason, the grid will rebind to the first page and the pager should show correctly.
I generally find it better to not put in Try/Catch blocks too early in the development process, simply because I want the page to crash and I can track down the errors easier. Put them in later, not at the end of development though.
Robert M. Teague
Senior Programmer/Analyst
Kamehameha Schools
http://www.ksbe.edu
Originally posted by roteague I think I see your problem. I think I have run into some similar to this in the past now that I think about it.
[cut]
Thanks roteague, your code is right, but it still doesn't solve the problem, because I don't really gat caught up in error, just the index of the number shown on pager it's wrong after the page has rendered.
Byez
snip: with default paging you cannot use a DataReader, but instead must use a DataTable or DataSet; using a DataReader will result in an exception. The reason you cannot use a DataReader is because the DataGrid needs to be able to determine how many total records are in the DataSource so it can determine how many total pages there are.
Robert M. Teague
Senior Programmer/Analyst
Kamehameha Schools
http://www.ksbe.edu
Currently I'm using Web Services, which returns an array of data
I wonder if that could be where the problem is happening. The datagrid needs to be able to step forward and backwards in order to figure out how to set up the pager. I'll have to check some of my Webservices stuff.
Robert M. Teague
Senior Programmer/Analyst
Kamehameha Schools
http://www.ksbe.edu
Originally posted by roteague I wonder if that could be where the problem is happening. The datagrid needs to be able to step forward and backwards in order to figure out how to set up the pager. I'll have to check some of my Webservices stuff.
Thank you very much roteague, I'll also keep you informed if I make progress in this situation
Aloha! (about your place...aah, what a beautiful place )
Bookmarks