Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi. I'm using this code to try and sort my GridView without a DataSource. The problem is I don't think my GridView is getting populated. Whenever I click on the Column header nothing happen. No Error message etc.

This is the code I'm using. Please let me know if you need more info from me...

VB
Private Function ConvertSortDirectionToSql(ByVal sortDirection As SortDirection) As String
       Dim newSortDirection As String = String.Empty

       Select Case SortDirection
           Case SortDirection.Ascending
               newSortDirection = "ASC"

           Case SortDirection.Descending
               newSortDirection = "DESC"
       End Select

       Return newSortDirection
   End Function

   Protected Sub grdEmp_Sorting(sender As Object, e As GridViewSortEventArgs) Handles grdEmp.Sorting


       Dim dataTable As DataTable = TryCast(grdEmp.DataSource, DataTable)

       If Not dataTable Is Nothing Then
           MsgBox("Not Empty")
           Dim dataView As DataView = New DataView(dataTable)
           dataView.Sort = e.SortExpression & " " & ConvertSortDirectionToSql(e.SortDirection)

           grdEmp.DataSource = dataView
           grdEmp.DataBind()
       ElseIf dataTable Is Nothing Then
           MsgBox("Empty")
       End If



Thanks for your help..
Posted
Updated 15-Nov-13 8:03am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900