Gridview Sorting is not Working Since Datatable is Empty
Code: Dim dt As DataTable = TryCast(GRDV.DataSource, DataTable)
above code is returning Empty Gridview ..
Please help me
My code is below
Protected Sub GRDV_Sorting(sender As Object, e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles StudentAssignmentgridview.Sorting
'If showImage = False Then
' showImage = True
'End If
Dim dt As DataTable = TryCast(GRDV.DataSource, DataTable)
If dt IsNot Nothing Then
Alert.Show(e.SortExpression)
Dim dv As New DataView
dv = New DataView(dt)
dv.Sort = e.SortExpression & " " & GetSortDirection()
GRDV.DataSource = dv
GRDV.DataBind()
Else
Alert.Show("Nothing")
' MsgBox("Nothing", MsgBoxStyle.OkOnly, "SA")
End If
End Sub
Private Property GridViewSortDirection() As String
Get
Return If(TryCast(ViewState("SortDirection"), String), "DESC")
End Get
Set(value As String)
ViewState("SortDirection") = value
End Set
End Property
Private Function GetSortDirection() As String
Select Case GridViewSortDirection
Case "ASC"
GridViewSortDirection = "DESC"
Exit Select
Case "DESC"
GridViewSortDirection = "ASC"
Exit Select
End Select
Return GridViewSortDirection
End Function