I was playing with the paging technique for sql server 2k5 (article posted by graz on the main page). I setup my datagridview (visual studio.net 2k5 btw) to allow for paging. I want my page size to be 5 and to start with page number one.I wrote up some code to pass in the page size and page number into a sproc:Imports System.Data.SqlClientPartial Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then BindData(5, 1) End If End Sub Public Sub BindData(ByVal pSize As Integer, ByVal pNumber As Integer) Dim sConn As SqlConnection Dim cmdSelect As SqlCommand Dim da As SqlDataAdapter Dim ds As Data.DataSet Try sConn = New SqlConnection("User ID=joeblow;Password=somePass;Initial Catalog=CData;Data Source=SQL-1;") cmdSelect = New SqlCommand("selData", sConn) With cmdSelect .CommandType = Data.CommandType.StoredProcedure 'add parameters .Parameters.Add("@PageSize", Data.SqlDbType.Int).Value = pSize .Parameters.Add("@PageNumber", Data.SqlDbType.Int).Value = pNumber da = New SqlDataAdapter da.SelectCommand = cmdSelect ds = New Data.DataSet da.Fill(ds) End With With Me.GridView1 .DataSource = ds.Tables(0) If ds.Tables(0).Rows.Count = 0 Then Me.GridView1.Visible = False GridView1.DataSource = Nothing End If .DataBind() .Visible = True .AllowPaging = True End With Catch e As Exception Response.Write("An Error Occurred: " & e.ToString()) 'clean up and close resources Finally ds = Nothing da = Nothing cmdSelect = Nothing sConn.Close() sConn = Nothing End Try End Sub Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging Me.GridView1.PageIndex = e.NewPageIndex BindData(5, e.NewPageIndex + 1) End SubEnd Class
When I run the code, the grid displays the first 5 results which looks good. I have about 20 test records in the database. The issue is I do not see the pager on the bottom of the datagridview. I do see it when I modify my code to set the pagesize to 100...Then I see the page numbers 1,2,3,4,... etc. However why would that be ? I dont want to set the page size to 100 as I only want to see 5 rows per page. Or is the page size referring to something different ?
Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]RS Blog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]