Hi,
I have a gridview and i would like sort this gridview. The problem is, datatable is empty. Here is the code; How can i make this work?
thanks in advance.
Best Regards
I have a gridview and i would like sort this gridview. The problem is, datatable is empty. Here is the code; How can i make this work?
thanks in advance.
Best Regards
VB.NET:
Protected Sub gridView_Sort(ByVal sender As Object, ByVal e As GridViewSortEventArgs)
[B]Dim dataTable As DataTable = CType(GridView1.DataSource, DataTable)[/B]
If Not IsNothing(dataTable) Then
Dim dataView As New DataView(dataTable)
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection)
GridView1.DataSource = dataView
GridView1.DataBind()
End If
End Sub
Private Function ConvertSortDirectionToSql(ByVal sortDirection As SortDirection) As String
Dim newSortDirection As String = String.Empty
Select Case sortDirection
Case sortDirection.Ascending
newSortDirection = "ASC"
Exit Select
Case sortDirection.Descending
newSortDirection = "DESC"
Exit Select
End Select
Return newSortDirection
End Function