Datagrid paging wierd behaviour

Discussion in 'ASP .Net Datagrid Control' started by Brian Lowe, Oct 23, 2006.

  1. Brian Lowe

    Brian Lowe Guest

    I have a DataGrid which uses a dataset as its source. I have it set to allow
    paging and page length set at 9 rows, and page style set to numeric. My
    dataset has 25 rows, so just as expected I see rows 1 to 9 and paging links
    1 to 3 with "1" as a static label and "2" and "3" as linkbuttons.

    OK - here's where the fun starts.

    I click "2" and get a postback, but the grid still shows rows 1 to 9 and
    the paging controls still show 1 as static and 2 and 3 as active links.

    I click "2" a second time. The grid still shows rows 1 to 9 but the paging
    controls change so that 1 is active, 2 is static and 3 is active.

    But the wierdness doesn't stop there.

    I click "3". The grid still shows rows 1 to 9 but the paging controls change
    so that 1 is still active, 2 is still static and 3 is still active.

    I click "3" again. The grid now shows rows 1 to 7 and the paging controls
    change so that 1 is still active, 2 is now active and 3 is now static.

    OK - so I figure that the grid has somehow clocked the fact that it should
    only be showing 7 rows because it's on page 3, but how come it's showing
    rows belonging to page 1?

    Now, "1" is an active link, so I click it, and then the grid content changes
    to show rows 1 to 8 and some columns of row #9.

    I've looked at the code and it seems to match exactly the examples (aside
    from the structure of the test dataset) on MSDN and various other coding
    support sites.

    I've set Trace="True" and watched the output and can see nothing different
    in my page to what's in a (really over simplistic) example.

    I've stepped through the code line by line in the Visual Studio IDE. Nothing
    raises any errors. Everything seems to happen just when it should.

    I've searched Google, MSDN et al for anything that might discuss symptoms
    similar to these, and I'ev drawn a blank.

    I just know I'm going to look stupid when the cause is revealed to be
    something obvious and trivial, but what the heck. Nothing's idiot proof to a
    really talented idiot!

    Brian
    Brian Lowe, Oct 23, 2006
    #1
    1. Advertising

  2. Brian Lowe

    Scott M. Guest

    The problem is most likely where and when you are calling DataBind in your
    code.

    Your Page_Load event should only do a databind in a NON postback situation
    (although the data source should be set in either case). The DataBind call
    should also be placed in your PageIndexChanged event handler after setting
    the new page index.

    Let's see your code.



    "Brian Lowe" <> wrote in message
    news:...
    >I have a DataGrid which uses a dataset as its source. I have it set to
    >allow paging and page length set at 9 rows, and page style set to numeric.
    >My dataset has 25 rows, so just as expected I see rows 1 to 9 and paging
    >links 1 to 3 with "1" as a static label and "2" and "3" as linkbuttons.
    >
    > OK - here's where the fun starts.
    >
    > I click "2" and get a postback, but the grid still shows rows 1 to 9 and
    > the paging controls still show 1 as static and 2 and 3 as active links.
    >
    > I click "2" a second time. The grid still shows rows 1 to 9 but the paging
    > controls change so that 1 is active, 2 is static and 3 is active.
    >
    > But the wierdness doesn't stop there.
    >
    > I click "3". The grid still shows rows 1 to 9 but the paging controls
    > change so that 1 is still active, 2 is still static and 3 is still active.
    >
    > I click "3" again. The grid now shows rows 1 to 7 and the paging controls
    > change so that 1 is still active, 2 is now active and 3 is now static.
    >
    > OK - so I figure that the grid has somehow clocked the fact that it should
    > only be showing 7 rows because it's on page 3, but how come it's showing
    > rows belonging to page 1?
    >
    > Now, "1" is an active link, so I click it, and then the grid content
    > changes to show rows 1 to 8 and some columns of row #9.
    >
    > I've looked at the code and it seems to match exactly the examples (aside
    > from the structure of the test dataset) on MSDN and various other coding
    > support sites.
    >
    > I've set Trace="True" and watched the output and can see nothing different
    > in my page to what's in a (really over simplistic) example.
    >
    > I've stepped through the code line by line in the Visual Studio IDE.
    > Nothing raises any errors. Everything seems to happen just when it should.
    >
    > I've searched Google, MSDN et al for anything that might discuss symptoms
    > similar to these, and I'ev drawn a blank.
    >
    > I just know I'm going to look stupid when the cause is revealed to be
    > something obvious and trivial, but what the heck. Nothing's idiot proof to
    > a really talented idiot!
    >
    > Brian
    >
    >
    >
    >
    >
    >
    Scott M., Oct 23, 2006
    #2
    1. Advertising

  3. Brian Lowe

    Brian Lowe Guest

    I was following an example in C# that just had
    void dataGrid1_PageIndexChanged(object source,
    System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {
    dataGrid1.CurrentPageIndex = e.NewPageIndex;
    }
    in its code, and which seemed to work just fine.

    I hadn't noticed that elsewhere in the code file were
    void Page_Load()
    {
    dataGrid1.DataSource = DataView1;
    }
    void Page_PreRender()
    {
    DataBind();
    }

    I've changed my code so that the DataSource is set and the DataBind gets
    triggered, and now all is well.

    Thanks

    "Scott M." <> wrote in message
    news:<#>...
    > The problem is most likely where and when you are calling DataBind in your
    > code.
    > Your Page_Load event should only do a databind in a NON postback situation
    > (although the data source should be set in either case). The DataBind call
    > should also be placed in your PageIndexChanged event handler after setting
    > the new page index.
    > Let's see your code.
    Brian Lowe, Oct 26, 2006
    #3
    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. Simon

    Wierd DataGrid behaviour

    Simon, Nov 5, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    358
    Simon
    Nov 5, 2003
  2. PSN
    Replies:
    3
    Views:
    366
  3. Vaddina Prakash Rao

    Wierd behaviour of function 'strcspn'

    Vaddina Prakash Rao, Dec 17, 2004, in forum: C Programming
    Replies:
    2
    Views:
    335
    Dave Thompson
    Dec 20, 2004
  4. Cirene

    Wierd paging issues with Gridview

    Cirene, Nov 29, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    314
    Cirene
    Nov 29, 2007
  5. SiWi
    Replies:
    3
    Views:
    804
    geremy condra
    Dec 9, 2009
Loading...

Share This Page