how to sort grid view with paging function

Posted by Prakashrajmca under VB.NET on 12/28/2011 | Points: 10 | Views : 1781 | Status : [Member] | Replies : 1
hi,
any one tell me how to sort gridview in vb.net, ( instead of sql db i used different one)
something missing in my coding i could not find out what i missed ( or give your own code how to sort the data)
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Private Function Convertsqldir(ByVal sortdirection As SortDirection) As String
Dim newsortdirection = String.Empty
MsgBox(sortdirection)
Select Case sortdirection
Case sortdirection.Ascending
newsortdirection = "ASC"
Case sortdirection.Descending
newsortdirection = "DESC"
End Select
MsgBox(newsortdirection.ToString())

Return newsortdirection

End Function
---------------------------------
Protected Sub gridview1_sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles Gvemp1.Sorting
Try
Dim ds As New DataSet

Dim connection As New CacheConnection()
connection.ConnectionString = "Server=localhost;Port=1972;Namespace=TEST;User ID=_SYSTEM; password=a12345"
connection.Open()
' MsgBox(connection.State.ToString())
Dim da As New CacheDataAdapter
Dim cmd As CacheCommand
cmd = connection.CreateCommand()
cmd.CommandText = "select ID,Name,Dob,Age,Designation,Branch,Address->Phonenumber as Phonenumber,Address->Street as Street,Address->Pinnumber as Pinnumber,Address->City as City,Address->State as State from Employee.Details"
da.SelectCommand = cmd
Dim table As New DataTable
Dim dv As New DataView
da.Fill(table)
dv = table.DefaultView
dv.Sort = e.SortExpression + " " + Convertsqldir(e.SortDirection)
Gvemp1.DataSource = dv
Gvemp1.DataBind()
ds.Dispose()
da.Dispose()
Catch ex As Exception
MsgBox(ex.Message.ToString())
End Try
End Sub




Responses

Posted by: Blessyjees on: 1/19/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi,

Have you set the sortexpression and sortdirection of the gridview?

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Prakashrajmca, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response