?
Solved

Gridview sort reloads original page

Posted on 2010-11-27
5
Medium Priority
?
524 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

764 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