473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
7 1107
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ck388 | last post by:
For some reason when I enable the callback feature of the gridview I still get a page refresh, that is it seems like there is a postback that occurs, not a callback which is just supposed to update...
2
by: asad | last post by:
Hello friends, i am designing a ASP.NET page where i want to use custom paging bcoz data is too heavy so pls tell me how can i use custom paging in ASP.NET Thanks
1
by: ck388 | last post by:
For some reason when I enable the callback feature of the gridview I still get a page refresh, that is it seems like there is a postback that occurs, not a callback which is just supposed to update...
0
by: ck388 | last post by:
For some reason when I enable the callback feature of the gridview I still get a page refresh, that is it seems like there is a postback that occurs, not a callback which is just supposed to update...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.