Asked by:
Column Sort Links

Question
-
User-1025482824 posted
Hello, I am following this tutorial for my sorting, paging, and filtering of my data. Tutorial
As you can see in the tutorial they use the code:
var students = from s in db.Students select s;
This statement is selecting a table from the database to gather the data that's going to be displayed in ascending and descending order. How would I add the ascending and descending column sort links from a data source that's not a database? Is that possible? If someone could point me to a tutorial or has some advice I'd love to hear it. Thank you in advance.
Monday, June 18, 2018 3:22 AM
All replies
-
User1992938117 posted
You know the column to be sorted for e.g. its "FirstName", then the query will be:
var students = from s in db.Students orderby s.FirstName select s;
http://www.tutorialsteacher.com/linq/linq-sorting-operators-orderby-orderbydescending
Monday, June 18, 2018 12:49 PM -
User-1025482824 posted
Thanks for example I read through it and my question is what about a list that is not coded/created in Visual Studio?
Monday, June 18, 2018 1:23 PM -
User1992938117 posted
what about a list that is not coded/created in Visual Studio?Do you have any example? Instead of db.Students you your own list.
Monday, June 18, 2018 2:25 PM -
User-1025482824 posted
It is basically data from an online item catalog/database.
Monday, June 18, 2018 2:43 PM -
User1992938117 posted
Sorry I don't have any idea of Catalog/Database, But I am sure that if you can fill the data in Data Table/Data Set or in a List then surely you can short it the way you need.
Tuesday, June 19, 2018 5:20 AM -
User-330142929 posted
Hi tkhan17,
How would I add the ascending and descending column sort links from a data source that's not a database? Is that possible?
Absolutely. we usually use LINQ to sort, filter, page the data source.
If your data source is database or MS access file, you could get records by ORM
Framework, such as: Entityframework, Ado.net, then use LINQ query. If your data source is a dynamically created list, you should get these list and then use the LINQ query.
It is basically data from an online item catalog/database.
In addition, if you have other data sources, please provide more details to make me clear about it. It is easy to give you a solution effectively if you could post more details about your codes.
Best Regards,
Abraham
Tuesday, June 19, 2018 8:04 AM