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 DataGridSortCommandEventAr gs)
Dim SortExpression As String
SortExpression = e.SortExpression.ToString( )
Dim odataView as DataView = GenerateSource().DefaultVi ew
odataView.Sort=SortExpress ion
datagrid1.DataSource=odata View
datagrid1.DataBind()
End Sub 'Sort_Grid
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 DataGridSortCommandEventAr
Dim SortExpression As String
SortExpression = e.SortExpression.ToString(
Dim odataView as DataView = GenerateSource().DefaultVi
odataView.Sort=SortExpress
datagrid1.DataSource=odata
datagrid1.DataBind()
End Sub 'Sort_Grid
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 DataGridSortCommandEventAr gs)
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().DefaultVi ew
odataView.Sort=SortExpress ion
datagrid1.DataSource=odata View
datagrid1.DataBind()
End Sub 'Sort_Grid
-tushar
Public Shared SortMode As String = "DESC"
Now modify your Sub like following;
Sub Sort_Grid(sender As Object, e As DataGridSortCommandEventAr
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().DefaultVi
odataView.Sort=SortExpress
datagrid1.DataSource=odata
datagrid1.DataBind()
End Sub 'Sort_Grid
-tushar
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
'----------
'---------- Add this portion in your code --------------
If SortMode = "Desc" Then
SortMode = "Asc"
SortExpression = SortExpression + " " + "Desc"
Else
SortMode = "Desc"
End If
'----------
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\adheren ce\Repsche d.aspx Line: 65
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\adheren
DId you include this line with your Class Declaration?
Public Shared SortMode As String = "Asc"
-tushar
Public Shared SortMode As String = "Asc"
-tushar
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=odata View
Line 84: datagrid1.DataBind()
Line 85: End Sub 'Sort_Grid
Source File: c:\inetpub\wwwroot\adheren ce\Repsche d.aspx Line: 83
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=odata
Line 84: datagrid1.DataBind()
Line 85: End Sub 'Sort_Grid
Source File: c:\inetpub\wwwroot\adheren
ASKER
tusharashah,
Got it !!
there was multiple end sub.
Thanks so much for your time and patience.
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
regards,
KS
ASKER
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 DataGridSortCommandEventAr
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().DefaultVi
odataView.Sort=SortExpress
datagrid1.DataSource=odata
datagrid1.DataBind()
End Sub 'Sort_Grid