Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Datagrid paging wierd behaviour

Reply
Thread Tools

Datagrid paging wierd behaviour

 
 
Brian Lowe
Guest
Posts: n/a
 
      10-23-2006
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






 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      10-23-2006
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
>
>
>
>
>
>



 
Reply With Quote
 
 
 
 
Brian Lowe
Guest
Posts: n/a
 
      10-26-2006
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-> 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.



 
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
Wierd paging issues with Gridview Cirene ASP .Net 1 11-29-2007 06:53 PM
Combining numeric mode paging and nextPreview paging in datagrid Red ASP .Net 1 03-12-2005 11:41 PM
Wierd Behaviour: Crash at 'delete' of memory. PSN C++ 3 03-09-2005 06:15 PM
datagrid paging - customising paging style wh1974 ASP .Net 0 01-12-2005 03:48 PM
Wierd DataGrid behaviour Simon ASP .Net 0 11-05-2003 05:40 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57