Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Datagrid Control (http://www.velocityreviews.com/forums/f60-asp-net-datagrid-control.html)
-   -   Datagrid paging wierd behaviour (http://www.velocityreviews.com/forums/t763037-datagrid-paging-wierd-behaviour.html)

Brian Lowe 10-23-2006 01:00 PM

Datagrid paging wierd behaviour
 
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. 10-23-2006 03:52 PM

Re: Datagrid paging wierd behaviour
 
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" <brian_lowe@ntlworld.com> wrote in message
news:OUAF0Mq9GHA.1168@TK2MSFTNGP03.phx.gbl...
>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 10-26-2006 12:11 PM

Re: Datagrid paging wierd behaviour
 
I was following an example in C# that just had
void dataGrid1_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEvent Args 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." <s-mar@nospam.nospam> wrote in message
news:<#NCypsr9GHA.896@TK2MSFTNGP03.phx.gbl>...
> 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.





All times are GMT. The time now is 03:20 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.