Sorting Linq Query Objects
Posted: Wed 20 May 2009 14:02
I have a Linq Query stored in session and bound to a gridview like this:
Each Time a user clicks a column header, I would like to sort the query. This would be the normal way I would do it if it was a dataTable stored in session:
What is the alternative way to make this work with LINQ?
Code: Select all
gvResults.DataSource = persons
gvResults.DataBind()
Session("PERSONS") = persons
Code: Select all
Dim dt As DataTable = Session("PERSONS")
Dim dv As DataView = New DataView(dt)
dv.Sort = sortEx
'Save back to Session so paging functionality remains
Session("PERSONS") = dv.ToTable()
gvResults.DataSource = Session("PERSONS")
gvResults.DataBind()