我有一个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上没有发生任何事情仍然没有排序还有另一种排序方法吗?
答案 0 :(得分:2)
在列
中定义变量类型tb.Columns.Add("FileName", typeof(String))
tb.Columns.Add("FileCreationTime",typeof(DateTime))
DataTable DateTime列排序: