Problem with Sorting AND Paging in a GridView

Problem with Sorting AND Paging in a GridView

am 01.04.2008 23:00:37 von gnewsgroup

I have a GridView, with sorting and paging enabled.

The GridView is bound in code-behind, where I also have the sorting
and paging event handlers.

Both sorting and paging seem to be working fine, but the problem is,
if I click on a page index, the sorting order is reversed. To make it
clear, suppose my GridView has 4 pages like below:

Page 1:

A
B
C

Page 2:

D
E
F

Page3:

G
H
I

Page 4:

J
K
L

If I click on the table header, the data gets sorted, fine, like so:

Page 1:

L
K
J

But, if I then click on the page index 2, I see this:

Page 2:

D
E
F

Whereas, I am expecting to see this:

Page 2:

I
H
G

See the problem? How to overcome this? Thanks.

RE: Problem with Sorting AND Paging in a GridView

am 02.04.2008 03:13:01 von pbromberg

store the current sort order in ViewState, then pull it back out and set the
sort just before rebinding the Grid on a new page.
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short Urls & more: http://ittyurl.net


"gnewsgroup" wrote:

> I have a GridView, with sorting and paging enabled.
>
> The GridView is bound in code-behind, where I also have the sorting
> and paging event handlers.
>
> Both sorting and paging seem to be working fine, but the problem is,
> if I click on a page index, the sorting order is reversed. To make it
> clear, suppose my GridView has 4 pages like below:
>
> Page 1:
>
> A
> B
> C
>
> Page 2:
>
> D
> E
> F
>
> Page3:
>
> G
> H
> I
>
> Page 4:
>
> J
> K
> L
>
> If I click on the table header, the data gets sorted, fine, like so:
>
> Page 1:
>
> L
> K
> J
>
> But, if I then click on the page index 2, I see this:
>
> Page 2:
>
> D
> E
> F
>
> Whereas, I am expecting to see this:
>
> Page 2:
>
> I
> H
> G
>
> See the problem? How to overcome this? Thanks.
>