Link to home
Start Free TrialLog in
Avatar of lynnton
lynnton

asked on

sort

Hi,

Presently user clicks the header and it arrange to ascending order, how can we make that when the user clicks again o nthe same column it would now do descending?

Thanks.

    Sub Sort_Grid(sender As Object, e As DataGridSortCommandEventArgs)
        Dim SortExpression As String
        SortExpression = e.SortExpression.ToString()
        Dim odataView as DataView = GenerateSource().DefaultView
         odataView.Sort=SortExpression
         datagrid1.DataSource=odataView
        datagrid1.DataBind()
    End Sub 'Sort_Grid
SOLUTION
Avatar of Ramesh Srinivas
Ramesh Srinivas
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lynnton
lynnton

ASKER

saleek,

Is it okay if you could kindly guide me with the poper integration from the below to use your format?

Thanks.

Sub Sort_Grid(sender As Object, e As DataGridSortCommandEventArgs) Handles DataGrid1.SortCommand
        Dim SortExpression As String

 If Me.sortCriteria = e.SortExpression Then
            If Me.sortDir = "desc" Then
                Me.sortDir = "asc"
            Else
                Me.sortDir = "desc"
            End If
        End If

        SortExpression = e.SortExpression.ToString()
        Dim odataView as DataView = GenerateSource().DefaultView
         odataView.Sort=SortExpression
         datagrid1.DataSource=odataView
        datagrid1.DataBind()
    End Sub 'Sort_Grid

Declare a variable with your other class declaration as shared ( i think that is equivalent to Static in C#):

Public Shared SortMode As String = "DESC"

Now modify your Sub like following;

Sub Sort_Grid(sender As Object, e As DataGridSortCommandEventArgs)
        Dim SortExpression As String
        SortExpression = e.SortExpression.ToString()
'---------- Add this portion in your code --------------
        If SortMode = "Desc" Then
             SortMode = "Asc"
             SortExpression = SortExpression + " " + "Desc"
        End If  
'----------
        Dim odataView as DataView = GenerateSource().DefaultView
         odataView.Sort=SortExpression
         datagrid1.DataSource=odataView
        datagrid1.DataBind()
    End Sub 'Sort_Grid


-tushar
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm sorry... prolly i need a coffee...

'---------- Add this portion in your code --------------
        If SortMode = "Desc" Then
          SortMode = "Asc"
          SortExpression = SortExpression + " " + "Desc"
        Else
          SortMode = "Desc"
        End If
'----------
Avatar of lynnton

ASKER

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'SortMode' is not declared.
Source Error:
Line 63:             SortExpression = e.SortExpression.ToString()
Line 64:    
Line 65:             If SortMode = "Desc" Then
Line 66:               SortMode = "Asc"
Line 67:               SortExpression = SortExpression + " " + "Desc"
Source File: c:\inetpub\wwwroot\adherence\Repsched.aspx    Line: 65
DId you include this line with your Class Declaration?

Public Shared SortMode As String = "Asc"


-tushar
Avatar of lynnton

ASKER

I could make this one out, been trying lots of times to resolve this..


Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30188: Declaration expected.
Source Error:
Line 81:
Line 82:
Line 83:          datagrid1.DataSource=odataView
Line 84:         datagrid1.DataBind()
Line 85:     End Sub 'Sort_Grid
Source File: c:\inetpub\wwwroot\adherence\Repsched.aspx    Line: 83
Avatar of lynnton

ASKER

tusharashah,

Got it !!

there was multiple end sub.

Thanks so much for your time and patience.
Nice to have you going lynnton :)
Sorry lynnton, popped out for lunch! Glad you found a solution.

regards,

KS