Click here to Skip to main content
15,899,126 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:

VB
Dim dir As New DirectoryInfo("E:\Sample")
        GridView1.DataSource = dir.GetFiles()
        GridView1.DataBind()



Thanks&Regards
Hari
Posted
Updated 1-Nov-12 4:44am
v2
Comments
Nelek 1-Nov-12 10:36am    
I recommend you to read:
what have you tried?[^]
How to ask a question?[^]

And then use the widget "Improve question" to edit your text
Hari Krishna Prasad Inakoti 1-Nov-12 10:45am    
Thanq Nelek i forgot add the code in this question

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.
 
Share this answer
 
Comments
Hari Krishna Prasad Inakoti 7-Nov-12 6:52am    
Thanq very much .Nice Reply
VB
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900