Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Datagrid custom paging problem

Reply
Thread Tools

Datagrid custom paging problem

 
 
SStory
Guest
Posts: n/a
 
      09-19-2003
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.DataGridPageChangedEvent Args) Handles
grdSearchResults.PageIndexChanged

intStartIndex = (e.NewPageIndex * grdSearchResults.PageSize)
grdSearchResults.CurrentPageIndex = e.NewPageIndex
BindDataGrid()
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)
cmdSelect.Parameters.Add(p)
p = New SqlParameter("@PageNumber", intStartIndex)
cmdSelect.Parameters.Add(p)
p = New SqlParameter("@PerPage", RESULTS_PERPAGE)
cmdSelect.Parameters.Add(p)
daResults = New SqlDataAdapter(cmdSelect)
dsResults = New DataSet
daResults.Fill(dsResults, "Results")

grdSearchResults.DataSource = dsResults
grdSearchResults.DataBind()
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)
cmdSelect.Parameters.Add(p)
conn.Open()
'get size
grdSearchResults.VirtualItemCount = (cmdSelect.ExecuteScalar() /
grdSearchResults.PageSize)
grdSearchResults.PageSize = RESULTS_PERPAGE
conn.Close()
BindDataGrid()
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 Mode="NumericPages"></PagerStyle>
</asp:datagrid>

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

Shane


 
Reply With Quote
 
 
 
 
SStory
Guest
Posts: n/a
 
      09-19-2003
Forget 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:
http://www.microsoft.com/india/msdn/articles/83.aspx

Shane


"SStory" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.DataGridPageChangedEvent Args) Handles
> grdSearchResults.PageIndexChanged
>
> intStartIndex = (e.NewPageIndex * grdSearchResults.PageSize)
> grdSearchResults.CurrentPageIndex = e.NewPageIndex
> BindDataGrid()
> 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)
> cmdSelect.Parameters.Add(p)
> p = New SqlParameter("@PageNumber", intStartIndex)
> cmdSelect.Parameters.Add(p)
> p = New SqlParameter("@PerPage", RESULTS_PERPAGE)
> cmdSelect.Parameters.Add(p)
> daResults = New SqlDataAdapter(cmdSelect)
> dsResults = New DataSet
> daResults.Fill(dsResults, "Results")
>
> grdSearchResults.DataSource = dsResults
> grdSearchResults.DataBind()
> 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)
> cmdSelect.Parameters.Add(p)
> conn.Open()
> 'get size
> grdSearchResults.VirtualItemCount = (cmdSelect.ExecuteScalar() /
> grdSearchResults.PageSize)
> grdSearchResults.PageSize = RESULTS_PERPAGE
> conn.Close()
> BindDataGrid()
> 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 Mode="NumericPages"></PagerStyle>
> </asp:datagrid>
>
> I anyone has any ideas as to what I am doing wrong, please let me know.
>
> Shane
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining numeric mode paging and nextPreview paging in datagrid Red ASP .Net 1 03-12-2005 11:41 PM
DataGrid Custom Paging Problem =?Utf-8?B?UmFlZCBTYXdhbGhh?= ASP .Net 0 02-16-2005 11:35 AM
datagrid paging - customising paging style wh1974 ASP .Net 0 01-12-2005 03:48 PM
Problem with "Custom paging" of DataGrid control Alex ASP General 1 09-14-2003 04:10 PM
DataGrid Custom Paging using SQLDataReader Paul Hobbs ASP .Net 1 07-24-2003 04:00 PM



Advertisments