[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Gridview sort reloads original page

Posted on 2010-11-27
5
Medium Priority
?
528 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 16

Accepted Solution

by:
Kamal Khaleefa earned 1000 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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

650 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