1
Protected
Sub gvdatalist_Sorting()
Sub gvdatalist_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles gvdatalist.Sorting
2![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
3
GridViewSortExpression = e.SortExpression
4![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
Dim pageIndex As Integer = gvdatalist.PageIndex
6
gvdatalist.DataSource = SortDataTable(dt, False)
7
gvdatalist.DataBind()
8
gvdatalist.PageIndex = pageIndex
9![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
End Sub
11![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
Private
Property GridViewSortDirection()
Property GridViewSortDirection() As String
13
Get
14
Return ViewState("SortDirection")
15
End Get
16
Set(ByVal Value As String)
17
ViewState("SortDirection") = value
18
End Set
19
End Property
20![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
21![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
22![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
23![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
Private
Property GridViewSortExpression()
Property GridViewSortExpression() As String
24
Get
25
Return ViewState("SortExpression")
26
End Get
27
Set(ByVal Value As String)
28
ViewState("SortExpression") = value
29
End Set
30
End Property
31![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
32![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
33![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
34![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
Private
Function GetSortDirection()
Function GetSortDirection() As String
35![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
36
Select Case GridViewSortDirection
37![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
38
Case "ASC"
39
GridViewSortDirection = "DESC"
40![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
41
'Exit Function
42![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
43
Case "DESC"
44![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
45
GridViewSortDirection = "ASC"
46![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
47
' Exit Function
48
Case Else
49
GridViewSortDirection = "ASC"
50![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
51
End Select
52
Return GridViewSortDirection
53![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
54
End Function
55![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
56![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
57![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
58![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
59![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
Protected
Function SortDataTable()
Function SortDataTable(ByVal dataTable As DataTable, ByVal isPageIndexChanging As Boolean) As DataView
60![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
61
If Not dataTable Is Nothing Then
62![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
63
Dim dataView As DataView = New DataView(dataTable)
64![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
65
If GridViewSortExpression <> String.Empty Then
66![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
67
If isPageIndexChanging Then
68![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
69
dataView.Sort = String.Format("{0} {1}", GridViewSortExpression, GridViewSortDirection)
70![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
71
Else
72![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
73
dataView.Sort = String.Format("{0} {1}", GridViewSortExpression, GetSortDirection())
74![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
75
End If
76![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
77
End If
78![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
79
Return dataView
80![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
81
Else
82![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
83
Return New DataView()
84![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
85
End If
86![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
87
End Function
88![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
89![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
Protected
Sub gvdatalist_PageIndexChanging()
Sub gvdatalist_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvdatalist.PageIndexChanging
90
Me.gvdatalist.PageIndex = e.NewPageIndex
91
Me.gvdatalist.DataSource = SortDataTable(dt, True)
92
Me.gvdatalist.DataBind()
93
Me.drto.SelectedValue = e.NewPageIndex + 1
94
End Sub
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
27
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
28
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
29
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
30
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
31
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
32
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
33
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
34
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
35
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
36
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
37
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
38
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
39
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
40
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
41
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
42
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
43
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
44
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
45
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
46
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
47
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
48
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
49
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
50
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
51
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
52
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
53
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
54
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
55
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
56
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
57
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
58
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
59
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
60
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
61
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
62
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
63
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
64
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
65
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
66
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
67
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
68
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
69
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
70
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
71
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
72
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
73
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
74
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
75
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
76
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
77
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
78
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
79
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
80
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
81
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
82
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
83
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
84
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
85
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
86
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
87
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
88
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
89
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
90
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
91
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
92
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
93
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
94
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)