Solved

Gridview sort reloads original page

Posted on 2010-11-27
5
514 Views
Last Modified: 2012-05-10
Hello Experts,

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?

I'm using vb.net Thanks.

Gina
0
Comment
Question by:glomo82
5 Comments
 
LVL 16

Accepted Solution

by:
Kamal Khaleefa earned 250 total points
ID: 34224228
hi
this is depend on how you are doing the sorting
i will show a sample code here that i use


sub LoadUSERS()
dim dt as new datatable
    dt =   FindUsers()'a function that return a dt





            Dim dv As DataView = dt.DefaultView
            If Not ViewState("SortColumn") Is Nothing Then
                dv.Sort = (ViewState("SortColumn").ToString() + ViewState("SortDir").ToString()).ToString()
            End If

          

            GridView1.DataSource = dv
            GridView1.DataBind()
end sub

  Sub Sort(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim LinkButton1 As LinkButton = CType(sender, LinkButton)
        ViewState("SortColumn") = LinkButton1.ID.Substring(3).ToString
        ChangeSortDir()

        '  If ViewState("Type") Is Nothing Then ViewState("Type") = 1
        LoadUsers()
        'If ViewState("Type") = 1 Then
        '    LoadUsers() '1 means view all
        'Else
        '    If ViewState("Type") = 2 Then
        '        LoadUsers() '2 means search users
        '    Else
        '        LoadUsers() '3 means search directorate
        '    End If
        'End If

    End Sub

    Protected Sub ChangeSortDir()
        If ViewState("SortDir") Is Nothing Then
            ViewState("SortDir") = " ASC"
        Else
            If ViewState("SortDir").ToString() = " ASC" Then
                ViewState("SortDir") = " DESC"
            Else
                ViewState("SortDir") = " ASC"
            End If
        End If

    End Sub

Open in new window

0
 
LVL 12

Assisted Solution

by:Kaushal Arora
Kaushal Arora earned 250 total points
ID: 34227828
0
 

Author Comment

by:glomo82
ID: 34393526
Sorry this didn't work.   I goit to work by changing the SQl retrieval code.   Thank so much.
0
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 34421781
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question