排序表达式和排序方向 [英] Sort expression and the sort direction
本文介绍了排序表达式和排序方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有些人可以查看我的排序表达式,特别是排序方向:
Could someome check my sort expression especially the sort direction:
sortby = e.SortExpression & " " & sortingdirection
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
推荐答案
试试这个
Try this
sortingdirection = sortingdirection.Replace("Ascending","Asc").Replace("Descending","desc");
sortby = e.SortExpression & " " & sortingdirection
处理语法,因为我不知道 VB
。但问题是 Dataview
将接受Sorting参数为 ASC
和 DESC $ c仅限$ c>,但您传递
ENUM
为升序
和降序
...
希望你理解。
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.
这篇关于排序表达式和排序方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文