Datagrid custom paging problem

Discussion in 'ASP .Net Datagrid Control' started by SStory, Sep 19, 2003.

  1. SStory

    SStory Guest

    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
    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
    SStory, Sep 19, 2003
    #1
    1. Advertising

  2. SStory

    SStory Guest

    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" <> wrote in message
    news:...
    > 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
    > 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
    >
    >
    SStory, Sep 20, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UGF0cmljay5PLklnZQ==?=

    DataSet paging vs Datareader paging

    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=, Oct 8, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    10,659
    Scott Allen
    Oct 8, 2004
  2. wh1974
    Replies:
    0
    Views:
    2,419
    wh1974
    Jan 12, 2005
  3. =?Utf-8?B?UmFlZCBTYXdhbGhh?=

    DataGrid Custom Paging Problem

    =?Utf-8?B?UmFlZCBTYXdhbGhh?=, Feb 16, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    403
    =?Utf-8?B?UmFlZCBTYXdhbGhh?=
    Feb 16, 2005
  4. Red
    Replies:
    1
    Views:
    706
  5. Alex
    Replies:
    1
    Views:
    132
Loading...

Share This Page