发生的问题是在执行排序时无法找到Column。我试图用很多不同的代码对gridview进行排序。自从我开始排序已经有一周了。我试过跟随其他编码 但仍然会出现同样的错误。
Protected Sub SortRecords(sender As Object, e As GridViewSortEventArgs)
Dim dt As New DataTable(GridView1.DataSource)
Dim SortDir As String = String.Empty
Dim sortExpression As String = e.SortExpression
Dim sortedView As DataView = dt.DefaultView
If sortedView IsNot Nothing Then
If direction = SortDirection.Ascending Then
direction = SortDirection.Descending
SortDir = "Desc"
Else
direction = SortDirection.Ascending
SortDir = "Asc"
End If
sortedView.Sort = e.SortExpression & " " & SortDir 'error occur on this line
GridView1.DataSource = sortedView
GridView1.AllowSorting() = True
GridView1.DataBind()
End If
End Sub
问题出现在这一行:
sortedView.Sort = e.SortExpression & " " & SortDir