在排序gridview期间找不到列

时间:2016-04-21 01:18:42

标签: asp.net vb.net sorting gridview

发生的问题是在执行排序时无法找到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

0 个答案:

没有答案