By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,506 Members | 1,876 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,506 IT Pros & Developers. It's quick & easy.

Paging by example - help - still no luck....

P: n/a
Hello,

I was looking at the example provided on:
http://www.4guysfromrolla.com/webtech/072101-1.2.shtml
for paging.

I am using Visual Studio 2003 - Microsoft Development Environment 2003

For paging the page url mentions setting properties to be set as:

AllowPaging="True"
PageSize="15"
OnPageIndexChanged="dgPopularFAQs_Paged">

Ok. I am looking at my datagrid in the design view - there is a Allow
Paging, PageSize - but no OnPageIndexChanged!!

I went to the code behine - at the top selected my datagrid in the top
left drop down menu, and could not find OnPageIndexChanged in the
declarations menu. There is a 'PageIndexChanged' changed - is that it?

Well, I put this code in that area (using a Dataset called ds):
Private Sub dg_PageIndexChanged(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEvent Args) Handles
dg.PageIndexChanged
dg.CurrentPageIndex = e.NewPageIndex
dg.DataBind()
End Sub

The paging numbers show up on the grid, but when I hit any of the
numbers - the same screen shows up - 10 records, it does not advance
(set to 10 in the property builder). It never advances. In my page
load I have this:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then

dgDataBind()
End If
End Sub

Any help?

Thanks,

Tmuld

Nov 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Tmuld,

Why don't you just use the samples on MSDN for paging a datagrid, they are
in my opinion very well.

One of them
http://msdn.microsoft.com/library/de...isualBasic.asp

I hope this helps,

Cor
Nov 21 '05 #2

P: n/a
Thanks - it does work very well!

I still have some issues. I used the MSDN code and it sort of works.
Now the paging works, but when I hit the number - it does not show my
records until I hit the search button again. I thought it would go to
the next records automatically. Not sure why? Do I need to do some
sort of refresh at the button level?

[Plus I also do not understand this line:

dsQuery = CType(Session("dataset"), DataSet1). I already have a
dataset defined at design time - what does this do? ]

Here is my code:
- my dataset is called 'ds'

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
With dg
.AllowPaging = True
.PagerStyle.Mode = PagerMode.NumericPages
.PageSize = 5
.PagerStyle.PageButtonCount = 5
End With
If IsPostBack Then
ds = CType(Session("dataset"), DataSet1)
Else
daQuery.Fill(ds)
Session("dataset") = ds
DataBind()
End If
End Sub

The button code->filters out data with a dataview. So after the page
button is pressed - one gets a blank screen untill the button is
pressed again - then it moves to the next results.

Private Sub btn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn.Click
Dim Count As Integer

Dim dv As DataView = ds.Tables("DB").DefaultView
dv.RowFilter = "Title like '%" & txt.Text & "%' OR Address like
'%" & txt.Text & "%'"
Count = dv.Count
dg.DataSource = dv
dg.DataBind()
lblCount.Text = Count

End Sub

Paging:

Private Sub dg_PageIndexChanged(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEvent Args) Handles
dg.PageIndexChanged
dg.CurrentPageIndex = e.NewPageIndex
dg.DataBind()
End Sub

Nov 21 '05 #3

P: n/a
Tmuld,

A webpage is not persistent, what means that with every send and get back
all the data on serverside is removed. For that are some solutions for with
is the session the most simple. The most simple because it can fit
automatically (serialized) the dataset.

Therefore you have to set that dataset again when there is a postback to the
session (and as well when you do a fill to renew it).

Your other question is what I am always struggling with as well, so take
some time to find that.

Cor
Nov 21 '05 #4

P: n/a
It is strange it is actually working in the background, but only
appears after the search button is pressed again.

I am thinking the currentrowindex is updated, but only will show when
requeried.

I thought the Databind() property refreshed to the new index.

Still no luck....
Nov 21 '05 #5

P: n/a
Tmuld,

I made a complete working sample from that what I showed on MSDN in the
link.

Maybe you can try it.
\\\Needs only a webdagrid.
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds As DataSet
DataGrid1.AllowPaging = True
DataGrid1.PagerStyle.Mode = PagerMode.NumericPages
DataGrid1.PageSize = 5
DataGrid1.PagerStyle.PageButtonCount = 5
If IsPostBack Then
ds = DirectCast(Session("dataset"), DataSet)
DataGrid1.DataSource = ds
Else
ds = New DataSet
Dim dt As New DataTable
dt.Columns.Add("Mycolumn")
For i As Integer = 0 To 100
dt.LoadDataRow(New Object() {i.ToString}, True)
Next
ds.Tables.Add(dt)
Session("dataset") = ds
DataGrid1.DataSource = ds
DataBind()
End If
End Sub

Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e _
As System.Web.UI.WebControls.DataGridPageChangedEvent Args) _
Handles DataGrid1.PageIndexChanged
DataGrid1.CurrentPageIndex = e.NewPageIndex
DataGrid1.DataBind()
End Sub
///

I hope this helps a little bit?

Cor
Nov 21 '05 #6

P: n/a
Hey Cor! I appreciate that!

I tried that example - it is what I am using. I had to fiddle with the
placement of the databinds.

Of course now I have to get paging working and my select buttons on the
side are ignored!

Fix one thing - it leads to another issue!

Thanks for your time and help!

Tmuld

Nov 21 '05 #7

P: n/a
I mean sorting! Sorting is another strange animal.

And trying to make my BACK button work so it doesn't clear the grid
data and query. And of course asking the user to hit the 'back' button
on the browser is a "no go").

Tmuld

Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.