Solved

Gridview sort reloads original page

Posted on 2010-11-27
5
510 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
Comment Utility
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
Comment Utility
0
 

Author Comment

by:glomo82
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
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…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now