you need to set the OnSorting=""
property to some function name, and then handle the sorting in said function. something along these lines
Protected Sub TaskGridView_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs)
'Retrieve the table from the session object.
Dim dt = TryCast(Session("table"), DataTable)
If dt IsNot Nothing Then
'Sorting the data.
dt.DefaultView.Sort = e.SortExpression & " " & GetSortingDirection(e.SortExpression)
TaskGridView.DataSource = Session("TaskTable")
TaskGridView.DataBind()
End If
End Sub
Private Function GetSortingDirection(ByVal column As String) As String
' By default, set the sort direction to ascending.
Dim sortDirection = "ASC"
' Retrieve the last column that was sorted.
Dim sortExpression = TryCast(ViewState("SortExpression"), String)
If sortExpression IsNot Nothing Then
' Check if the same column is being sorted.
' Otherwise, the default value can be returned.
If sortExpression = column Then
Dim lastDirection = TryCast(ViewState("SortDirection"), String)
If lastDirection IsNot Nothing _
AndAlso lastDirection = "ASC" Then
sortDirection = "DESC"
End If
End If
End If
' Save new values in ViewState.
ViewState("SortDirection") = sortDirection
ViewState("SortExpression") = column
Return sortDirection
End Function