Paging to the next page always gives me the first page

Discussion in 'ASP .Net' started by cmrchs@gmail.com, Jul 23, 2008.

  1. Guest

    Hello,

    I have set the Allowpaging property to true in a standard DataGrid-
    control (System.Web.UI.WebControls).

    when run in the browser i get the first records in the first page,
    there are 5 pagesi n total, but when I click on the next page number,
    I always get the records of the first page ?

    how come?

    thank you
    Chris
     
    , Jul 23, 2008
    #1
    1. Advertising

  2. On Jul 23, 5:42 pm, "Patrice" <http://www.chez.com/scribe/> wrote:
    > Do you rebind your date to the grid on each postback ?
    >
    > <> a écrit dans le message de groupe de discussion :
    > ...
    >
    > > Hello,

    >
    > > I have set the Allowpaging property to true in a standard DataGrid-
    > > control (System.Web.UI.WebControls).

    >
    > > when run in the browser i get the first records in the first page,
    > > there are 5 pagesi n total, but when I click on the next page number,
    > > I always get the records of the first page ?

    >
    > > how come?

    >
    > > thank you
    > > Chris


    hello,

    Is that what you mean?

    public partial class _Default : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    DataGrid1.DataBind();
    }
    }
    but i still get the problem.

    what do you suggest?

    thank you
    Chris
     
    Christian Cambier, Jul 23, 2008
    #2
    1. Advertising

  3. On Jul 23, 7:30 pm, "Patrice" <http://www.chez.com/scribe/> wrote:
    > Let's restart fresh. This is not the expected behavior and we can't really
    > guess what you have done wrong without seeing some code.
    >
    > I would suggest to simplify your code as much as possible even possibly
    > providing a fictionous code constructed datatable as a data source and show
    > us the code around 20 lignes of code should be enough to reproduce this
    > problem.
    >
    > My guess was that the data are binded on each postback to the grid causing
    > the paging mechanism to be reset. But it seems this is not what you were
    > doing (my suggestion was about what the problem is, not how it should be
    > fixed, sorry for being unclear)...
    >
    > How do you bind those data ? Do you do this only on the first run or on each
    > postback ?
    >
    > --
    > Patrice
    >
    > "Christian Cambier" <> a écrit dans le message de
    > groupe de discussion :
    > ...
    >
    > > On Jul 23, 5:42 pm, "Patrice" <http://www.chez.com/scribe/> wrote:
    > >> Do you rebind your date to the grid on each postback ?

    >
    > >> <> a écrit dans le message de groupe de discussion :
    > >> ...

    >
    > >> > Hello,

    >
    > >> > I have set the Allowpaging property to true in a standard DataGrid-
    > >> > control (System.Web.UI.WebControls).

    >
    > >> > when run in the browser i get the first records in the first page,
    > >> > there are 5 pagesi n total, but when I click on the next page number,
    > >> > I always get the records of the first page ?

    >
    > >> > how come?

    >
    > >> > thank you
    > >> > Chris

    >
    > > hello,

    >
    > > Is that what you mean?

    >
    > > public partial class _Default : System.Web.UI.Page
    > > {
    > > protected void Page_Load(object sender, EventArgs e)
    > > {
    > > DataGrid1.DataBind();
    > > }
    > > }
    > > but i still get the problem.

    >
    > > what do you suggest?

    >
    > > thank you
    > > Chris


    thank you for your time!

    here's what i\ve done.

    In design mode: I drag a datagrid control on the webform. I configure
    the datasource using the wizard that appears so I specify:
    the data connection , the sql-select statement and that's it.

    the code generated in my webform1.aspx is:

    <%@ Page Language="C#" AutoEventWireup="true"
    CodeBehind="WebForm1.aspx.cs" Inherits="CSharpWebApp.WebForm1" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
    www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:DataGrid ID="DataGrid1" runat="server" AllowPaging="True"
    DataSourceID="SqlDataSource1">
    </asp:DataGrid>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$
    ConnectionStrings:NorthwindConnectionString %>"
    SelectCommand="SELECT * FROM [Products]"></asp:SqlDataSource>
    </form>
    </body>
    </html>

    and added in the code behind-file:
    protected void Page_Load(object sender, EventArgs e)
    {
    //if (! IsPostBack)
    DataGrid1.DataBind();
    }

    it doesn't work, with or without the commented line
    only the first records are shown.

    any ideas?

    Chris
     
    Christian Cambier, Jul 23, 2008
    #3
  4. Guest

    On Jul 23, 8:17 pm, "Patrice" <http://www.chez.com/scribe/> wrote:
    > Sorry. I just noticed you are really using a DataGrid ? Are you still using
    > .NET 1.1 ? 2.0 I would say as you are using a SqlDataSource which is likely
    > new also in 2.0.
    >
    > The DataGrid is AFAIK here mainly for legacy support. I would strongly
    > suggest to use a GridView instead. If you can then :
    > - replace your DataGrid control with a GridView.
    > - suppress the DataBind call, this is done for you when using a GridView
    > control
    >
    > and paging should work wihtout any other change !!!
    >
    > IMO the problem is that the DataGrid is AFAIK here mainly for legacy support
    > and perhaps doesn't support all the features against the newer data sources
    > (not sure but I believe we had to code for handling sorting and perhaps in
    > some cases paging depending on the datasource, this is doen automatically in
    > most if not all cases when using a GridView). I'm afraid that if you need to
    > keep using a DataGrid control you'll have to implement custom code to handle
    > paging.
    >
    > Is using a GridView acceptable ?
    >
    > --
    > Patrice


    I don't have any problems with the GridView.
    it's just that, I am preparing a course and in order to explain
    ADO.NET in detail, for me things can be explained more clearly using
    the DatGrid and SqlDataAdapter as I have done in the past.

    I guess I'll have to find another way to explain it.

    than you again for your time
    best regards
    Chris
     
    , Jul 23, 2008
    #4
  5. Guest

    On Jul 23, 8:17 pm, "Patrice" <http://www.chez.com/scribe/> wrote:
    > Sorry. I just noticed you are really using a DataGrid ? Are you still using
    > .NET 1.1 ? 2.0 I would say as you are using a SqlDataSource which is likely
    > new also in 2.0.
    >
    > The DataGrid is AFAIK here mainly for legacy support. I would strongly
    > suggest to use a GridView instead. If you can then :
    > - replace your DataGrid control with a GridView.
    > - suppress the DataBind call, this is done for you when using a GridView
    > control
    >
    > and paging should work wihtout any other change !!!
    >
    > IMO the problem is that the DataGrid is AFAIK here mainly for legacy support
    > and perhaps doesn't support all the features against the newer data sources
    > (not sure but I believe we had to code for handling sorting and perhaps in
    > some cases paging depending on the datasource, this is doen automatically in
    > most if not all cases when using a GridView). I'm afraid that if you need to
    > keep using a DataGrid control you'll have to implement custom code to handle
    > paging.
    >
    > Is using a GridView acceptable ?
    >
    > --
    > Patrice



    Patrice,

    is it still possible to use the sqlDataAdapter, 'cause adding it to
    the toolbox doesn't work (see post in this newsgroup "can not add the
    SqlDataAdapter to the toolbox ???")

    'cause without it i don't see how i can use the DataSet in the new
    method, with the GridView and SqlDataSource-control

    thank you
    Chris
     
    , Jul 23, 2008
    #5
  6. Guest

    On Jul 23, 8:30 pm, wrote:
    > On Jul 23, 8:17 pm, "Patrice" <http://www.chez.com/scribe/> wrote:
    >
    >
    >
    > > Sorry. I just noticed you are really using a DataGrid ? Are you still using
    > > .NET 1.1 ? 2.0 I would say as you are using a SqlDataSource which is likely
    > > new also in 2.0.

    >
    > > The DataGrid is AFAIK here mainly for legacy support. I would strongly
    > > suggest to use a GridView instead. If you can then :
    > > - replace your DataGrid control with a GridView.
    > > - suppress the DataBind call, this is done for you when using a GridView
    > > control

    >
    > > and paging should work wihtout any other change !!!

    >
    > > IMO the problem is that the DataGrid is AFAIK here mainly for legacy support
    > > and perhaps doesn't support all the features against the newer data sources
    > > (not sure but I believe we had to code for handling sorting and perhaps in
    > > some cases paging depending on the datasource, this is doen automatically in
    > > most if not all cases when using a GridView). I'm afraid that if you need to
    > > keep using a DataGrid control you'll have to implement custom code to handle
    > > paging.

    >
    > > Is using a GridView acceptable ?

    >
    > > --
    > > Patrice

    >
    > I don't have any problems with the GridView.
    > it's just that, I am preparing a course and in order to explain
    > ADO.NET in detail, for me things can be explained more clearly using
    > the DatGrid and SqlDataAdapter as I have done in the past.
    >
    > I guess I'll have to find another way to explain it.
    >
    > than you again for your time
    > best regards
    > Chris



    Patrice,

    is it still possible to use the sqlDataAdapter, 'cause adding it to
    the toolbox doesn't work (see post in this newsgroup "can not add the
    SqlDataAdapter to the toolbox ???")

    'cause without it i don't see how i can use the DataSet in the new
    method, with the GridView and SqlDataSource-control

    thank you
    Chris
     
    , Jul 23, 2008
    #6
    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. Deniz Bahar
    Replies:
    2
    Views:
    480
    Andrey Tarasevich
    Mar 9, 2005
  2. tconkling

    First statement always evaluated first?

    tconkling, Jul 9, 2005, in forum: C Programming
    Replies:
    3
    Views:
    331
    Keith Thompson
    Jul 9, 2005
  3. Oleg Ogurok

    Custom paging problems - first page always displayed

    Oleg Ogurok, Jul 8, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    124
    Oleg Ogurok
    Jul 8, 2003
  4. Infused
    Replies:
    3
    Views:
    291
    Infused
    Jun 27, 2007
  5. Marc
    Replies:
    6
    Views:
    126
    Michael Winter
    Apr 21, 2006
Loading...

Share This Page