Datagrid custom paging problem

Datagrid custom paging problem

Post by SStor » Sun, 21 Sep 2003 06:39:07

After tons of thinking I decided that a dataset for a search could contain
far too much info on the server for an ISP to allow, so I decided to do
custom paging.
I created a stored proc that makes a temporary table. It receives
PageNumber and PerPage properties and can receive a (just return count)
param to just get the count.

So page 1 if we are doing 5 per page would return
records 1,2,3,4,5
page 2 6,7,8,9,10 ,etc.

This all works--the records are based on the temp tables whose first field
is an Identity--only valid in the temp table.
Works great testing from Query Analyzer.

I have it binding to my datagrid and it shows the first page of data.
It doesn't show the page numbers though?
Just a 1.

There should be several pages.

Is that not automatic when it knows how many pages to use and pagenumbers is
turned on?

What am I missing here?

I have an event that handles
Private Sub grdSearchResults_PageIndexChanged(ByVal source As System.Object,
ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles

intStartIndex = (e.NewPageIndex * grdSearchResults.PageSize)
grdSearchResults.CurrentPageIndex = e.NewPageIndex
End Sub

most of this idea taken from ASP Unleashed book one and modified to use a
stored proc.

Am I doing something wrong?

Sub BindDataGrid()
Dim daResults As SqlDataAdapter
Dim dsResults As DataSet
intEndIndex = intStartIndex + grdSearchResults.PageSize
dim cmdSelect As SqlCommand = New SqlCommand("myStoredProcHere", conn)
cmdSelect.CommandType = CommandType.StoredProcedure
Dim p As New SqlParameter("@Rep_ID", Rep_ID)
p = New SqlParameter("@PageNumber", intStartIndex)
p = New SqlParameter("@PerPage", RESULTS_PERPAGE)
daResults = New SqlDataAdapter(cmdSelect)
dsResults = New DataSet
daResults.Fill(dsResults, "Results")

grdSearchResults.DataSource = dsResults
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim daResults As SqlDataAdapter
Dim dsResults As DataSet
Dim cmdSelect As SqlCommand

If Not IsPostBack Then
' Get Total Pages
cmdSelect = New SqlCommand("MyStoredProcHere", conn)
cmdSelect.CommandType = CommandType.StoredProcedure
p = New SqlParameter("@JustGetCount", 1)
'get size
grdSearchResults.VirtualItemCount = (cmdSelect.ExecuteScalar() /
grdSearchResults.PageSize = RESULTS_PERPAGE
End If
End Sub

'the HTML; the full declare has column definitions too--they work fine
<asp:datagrid id="grdSearchResults" runat="server" ForeColor="White"
Width="770px" AutoGenerateColumns="False"
AllowPaging="True" AllowSorting="True" AllowCustomPaging="True"
BackImageUrl="images/tablehdrbg.jpg" PageSize="3"
<PagerStyle Mode="NumericPages"></PagerStyle>

I anyone has any ideas as to what I am doing wrong, please let me know.


Datagrid custom paging problem

Post by SStor » Sun, 21 Sep 2003 08:15:23

orget it.

I found out that my stored proc was returning the number of pages--while
useful sometimes, the VirtualPageItemCount expects tot. record count.

Now it works.
Just have to make the page changes work.

Also discovered a great page on MS India for those needing the idea:


"SStory" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...