Pages

Tuesday, February 23, 2010

Sorting gridview bound with datatable



Protected Sub gvSorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs)

dtData = CType(Session("Data"), DataTable)
Dim dv As DataView = dtData.DefaultView
Dim sortdirection As String


If ViewState("direction") <> "" Then
sortdirection = ViewState("direction")
If sortdirection = "asc" Then
sortdirection = "desc"
Else
sortdirection = "asc"
End If
Else
sortdirection = "asc"
End If

dv.Sort = e.SortExpression + " " + sortdirection
dtData = dv.ToTable
ViewState("direction") = sd

gvwList.DataSource = dtData
gvwList.DataBind()


End Sub

No comments:

Post a Comment