Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

paging in vb 1

Status
Not open for further replies.

SBTBILL

Programmer
May 1, 2000
515
US
I'm trying to get paging to work. I either get the same page to just stay there or get the first page and when I hit the page number button everything vanishes.

Imports System.Data.OleDb
Imports System.Data.SqlTypes
Imports System.Data.SqlDbType
Imports system.Data.SqlClient
Imports system.Data
Imports System.ComponentModel
Imports System.Collections
Imports System.Web.UI.WebControls


Partial Class _Default
Inherits System.Web.UI.Page
Dim grabline As String
Dim ranks As New DataSet
Dim GRABTXT As New SqlConnection
Dim grab1 As New SqlCommand
Dim GRAB2 As New SqlCommand
'
Public GRAB As New SqlConnection("connection string")

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack Then

Else
Me.grdranks.AllowPaging = True
Me.grdranks.PageSize = 3
grabline = "Select rank_id, "
grabline = grabline + " female_rank_name "
grabline = grabline + " from distributors.dbo.rank "
grabline = grabline + " order by rank_id "
'
Dim grab1 As New SqlCommand(Me.grabline, GRAB)
'
Dim G1 As New SqlDataAdapter(grab1)
Dim G2 As New DataSet
'
Dim GAB As New SqlDataAdapter(grab1)
GAB.Fill(ranks, "THERANK")
'
Dim x3b = ranks.Tables("THERANK").Rows.Count
'
grdranks.DataSource = ranks.Tables("THERANK")
grdranks.DataBind()
'
grdranks.Visible = True
GRAB.Close()
End If
End Sub



Protected Sub grdranks_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles grdranks.PageIndexChanging
Dim grab1 As New SqlCommand(Me.grabline, GRAB)
'
Dim G1 As New SqlDataAdapter(grab1)
Dim G2 As New DataSet
'
Dim GAB As New SqlDataAdapter(grab1)
GAB.Fill(ranks, "THERANK")
grdranks.DataSource = ranks.Tables("THERANK")
grdranks.PageIndex = e.NewPageIndex
grdranks.DataBind()
grdranks.Visible = True

End Sub

Protected Sub grdranks_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdranks.PageIndexChanged

End Sub
End Class
 
what have you found doing a simple web search for "webforms, gridview paging"? this is where to start. what you will find is that the default paging for webform controls is terribly ineffecient. they page in code, which means all the data is pulled from the database and stored in veiwstate. that means all the data is sent to the browser, even if the user is only looking at 10 or so records at a time. and if there are 100s or 1000s of records...

searching the web with the phrase above will lead you to some sources for implementing database paging. at a high level you need
1. at least 1 query to pull back a page of data.
2. a another query to get the total count of items matching the criteria
with this information you can implement your own data source control that will efficiently query the database for a page of data.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
they page in code, which means all the data is pulled from the database and stored in veiwstate. that means all the data is sent to the browser, even if the user is only looking at 10 or so records at a time. and if there are 100s or 1000s of records...
That's a common misconception people have about viewstate, only the data that is relevant to the user's interaction with the GridView will be stored. So, in your simple scenario even if you return 1000 records from a database and just display 10, only those 10 records will have any related data in viewstate.

It's still inefficient to allow a GridView to control the paging, just not to the degree you think.

Mark,

Darlington Web Design
Experts, Information, Ideas & Knowledge
ASP.NET Tips & Tricks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top