Protected Sub SortRecords(sender As Object, e As GridViewSortEventArgs) Dim dv As New DataView(GridView1.DataSource) Dim SortDir As String = String.Empty Dim sortExpression As String = e.SortExpression If dv IsNot Nothing Then If direction = SortDirection.Ascending Then direction = SortDirection.Descending SortDir = "Desc" ViewState("SortExpression") = Convert.ToString(e.SortExpression & " " & SortDir) Else direction = SortDirection.Ascending SortDir = "Asc" ViewState("SortExpression") = Convert.ToString(e.SortExpression & " " & SortDir) End If End If 'BindGridView() dv.Sort = ViewState("SortExpression").ToString 'error happen here 'DataTable must be set prior to using DataView GridView1.DataSource = dv GridView1.AllowSorting = True GridView1.DataBind() End Sub
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)