I have done the changes what you suggested but the same result is getting ?
my Gridview sort only first time whn I click on nay column
I want ASC > DESC
Again DESC > ASC
and Again ASC > DESC this way my sort should work
I have changed my code
as you suggested i added Gridview binding to PAge_Load function
Code is below
Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim myUserInfo As GCS_User_Info = Session("UI")
If Not Page.IsPostBack Then
GRDView.DataSource = GetSortableData(String.Empty)
GRDView.DataBind()
End If
End Sub
Protected Sub GRDView_Sorting(sender As Object, e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GRDView.Sorting
GetSortableData(e.SortExpression)
End Sub
Public Function GetSortableData(ByVal Expression As String) As DataView
Dim dt As DataTable = TryCast(ViewState("Data1"), DataTable)
Dim dv As New DataView
If dt IsNot Nothing Then
dv = New DataView(dt)
dv.Sort = Expression & " " & GetSortDirection()
GRDView.DataSource = dv
GRDView.DataBind()
Else
Alert.Show("Nothing")
End If
Return dv
End Function
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