如何在vb.net中对gridview值进行排序? [英] How to sort the gridview values in vb.net?
本文介绍了如何在vb.net中对gridview值进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
如何在vb.net中对gridview值进行排序.我选择的sorting属性为true.但它不起作用.在我的GridView临时值r中.
我正在使用下面的代码读取文件夹并在gridview中显示该值工作正常.现在我想根据文件创建日期对该值进行排序.
请尽快回复.
代码是:
Hi All,
How to sort the gridview values in vb.net .I selected sorting property is true.But it is not working.In my GridView temporary values r there.
I''m using below code for reading folder and display that values in gridview it is working fine.Now i want to sort that values based on file creation date.
Please reply asap.
Code is:
Dim dir As New DirectoryInfo("E:\Sample")
GridView1.DataSource = dir.GetFiles()
GridView1.DataBind()
谢谢与问候
Hari
Thanks&Regards
Hari
推荐答案
您是否曾尝试在提出该问题之前先用Google对其进行搜索?这是一个非常基本的问题,您可以在Google上找到各种帮助.当我用Google搜索时出现的主要结果之一是GridView类的MSDN:
MSDN GridView类 [ MSDN GridView.Sort方法 [ ^ ]
它包含有关如何使其工作的代码示例.
Did you try to google this question before asking it? This is a very basic question and you can find all kinds of help for it on google. One of the main results that came up when I googled was the MSDN for the GridView class:
MSDN GridView Class[^]
I looked through the methods and found one called Sort:
MSDN GridView.Sort Method[^]
It includes code samples of how to get it to work.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objFSO = Server.CreateObject("Scripting.FileSystemObject")
Dim objFolder = objFSO.GetFolder("E:\Sample")
Dim dt As New DataTable
Dim FileName As DataColumn = New DataColumn("File Name")
FileName.DataType = System.Type.GetType("System.String")
Dim DateModified As DataColumn = New DataColumn("Date Modified")
DateModified.DataType = System.Type.GetType("System.DateTime")
dt.Columns.Add(FileName)
dt.Columns.Add(DateModified)
Dim objFile
For Each objFile In objFolder.Files
Dim dr As DataRow
dr = dt.NewRow()
dr.Item("File Name") = objFile.Name
dr.Item("Date Modified") = objFile.DateLastModified
dt.Rows.Add(dr)
Next
Dim dv As DataView
dv = New DataView
dv = dt.DefaultView
dv.Sort = "Date Modified"
GridView1.DataSource = dt
GridView1.DataBind()
objFolder = Nothing
objFSO = Nothing
GridView1.Visible = True
Button1.Visible = False
Button2.Visible = True
End Sub
这篇关于如何在vb.net中对gridview值进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文