Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Could someome check my sort expression especially the sort direction:

VB
sortby = e.SortExpression & " " & sortingdirection


VB
Protected Sub GridView1_OnSorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs) Handles GridView1.Sorting
        Dim sortingdirection, sortby
        If e.SortDirection = SortDirection.Ascending Then
            sortingdirection = SortDirection.Descending
        Else
            sortingdirection = SortDirection.Ascending
        End If
        sortby = e.SortExpression & " " & sortingdirection
        Dim connStr, cmdStr As String
        connStr = "conn string works"
        cmdStr = "SELECT [ido],[JD],[Xecl3],[Yecl3],[Zecl3] FROM OrbitDates;"
        Dim MyDataSet As New DataSet
        Dim MyDataTable As New DataTable()
        Try
            Using conn As New SqlConnection(connStr)
                Using cmd As New SqlCommand(cmdStr, conn)
                    conn.Open()
                    cmd.ExecuteNonQuery()
                    Using MyDataAdaptor As New SqlDataAdapter(cmd)
                        MyDataAdaptor.Fill(MyDataSet)
                        MyDataTable = MyDataSet.Tables(0)
                        Dim MyDataView As New DataView(MyDataTable)
                        MyDataView.Sort = sortby
                        GridView1.DataSource = MyDataView
                        GridView1.DataBind()
                        GridView1.PageIndex = Convert.ToInt32(ViewState("pageIndex"))
                    End Using
                    conn.Close()
                    cmd.Dispose()
                    conn.Dispose()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
Posted
Comments
What is the exact issue?

1 solution

Try this

VB
sortingdirection =  sortingdirection.Replace("Ascending","Asc").Replace("Descending","desc");
                  sortby = e.SortExpression & " " & sortingdirection


take care of syntax, as i dont know VB. but the issue is Dataview will accept the Sorting parameter as ASC and DESC only, but you are passing the ENUM as Ascending and Descending...

Hope you understood.
 
Share this answer
 
v2
Comments
Rahul VB 8-Feb-14 14:42pm    
hi Karthik, how have you been? Thanks for the solution, i was going through grid view, but dont know VB.
Karthik_Mahalingam 8-Feb-14 22:13pm    
am fine
Rahul VB 9-Feb-14 9:43am    
:)
Rahul VB 11-Feb-14 13:25pm    
Hey Karthik, sorry to trouble you. I just wanted to ask you about some suggestions on ASP.net. Actually, my asp is weak. I started off reading about page life cycle and stuff, i read about the controls, now i am into caching. Long time ago i read about ajax. I feel that i must start reading Javascript too. How should i go about it? I have done projects in ASP.Net and rendered data on the web. But i need to dwelve deeper into the subject. Any suggestion would be help full. Thanks a ton.
Karthik_Mahalingam 11-Feb-14 22:36pm    
Hi Rahul,
I am in vaccation leave. On the way to Delhi in train. Will be back to banglore after 8 days. You can post this as a question.
- sent from windows phone

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