I have a repository that contains all of my LINQ queries for this project that I am working on. I am able to get the LINQ results to a DataTable and bind that to a gridview for displaying the data. Now I need to make the gridview sortable. I have set AllowSorting="true" and I have the OnSort event handled in a routine in the codebehind. The program makes it into the sorting routine just fine.
Is manual sort my only option or is there an easier way to sort the gridview in the OnSort handler?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
If you bind the GridView to a DataSourceControl then the sorting is taken care of for you. Otherwise you’re stuck with doing it manually.
Method 2
I ended up solving this problem using this example from MSDN and attaching my own datatable, which was acquired through a LINQ Query in my repository.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0