在gridview中排序文件创建时间

时间:2015-05-21 03:51:35

标签: vb.net gridview file-io

我有一个gridview,它从servermappath检索名称和文件creationdatetime的列表,并尝试按创建时间排序

    Function GetTable() As DataTable

        Dim filePaths() As String = getFiles(Server.MapPath("~/path/"), "*" + Session("Uauthen") + "*", SearchOption.AllDirectories)
        Dim tb As New DataTable()
        tb.Columns.Add("FileName")
        tb.Columns.Add("FileCreationTime")
        Dim dv As New DataView(tb)
  dv.Sort = "FileCreationTime DESC"
        Dim sortedDT As DataTable = dv.ToTable()

        'Dim files As List(Of ListItem) = New List(Of ListItem)
        For Each filePath As String In filePaths

            sortedDT.Rows.Add(Path.GetFileName(filePath), File.GetCreationTime(filePath).ToString("d MMM yyyy hh:mm:ss"))


        Next

        Return sortedDT

    End Function

但是在gridview上没有发生任何事情仍然没有排序还有另一种排序方法吗?

1 个答案:

答案 0 :(得分:2)

在列

中定义变量类型
tb.Columns.Add("FileName", typeof(String))
tb.Columns.Add("FileCreationTime",typeof(DateTime))

DataTable DateTime列排序:

http://forums.asp.net/p/1267353/2393006.aspx