Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to keep order on object in collection(List<>) in .net 2.0

Posted on 2009-05-20
2
Medium Priority
?
210 Views
Last Modified: 2013-11-07
Hello Expert,
In a web method I am returning DataSet from Sql server SP. I am handling pagination and sorting at SP level. It works fine.
In c# code I am populating collection(List<>) of class objects by looping through the DataSet. Data is being added to collection in order it is coming from SP. But when Calling applications displays results(looping thru collections) the sort order gots messed up. It doesnt keep sort order we passed from SP.
My guess is it is happening because List<> doesnt keep order of element in which they gets added .Am I correct?
If Answer is yes Do I need to do sort again at resultSet level  i.e Sorting of Collection. I am new to .net and would like to know what should be approch to handle sorting at response level if we have different sortFilters .
Thanks.
0
Comment
Question by:EmiliJ
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1500 total points
ID: 24436059
Why not use SortedList<>?
0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 24436576
As a matter of fact the list should keep the order for items added. My feeling is that whatever control is used to display items may screw this order. OK, this is a bit strange.

You might need sortedlist as kaufmed pointed. However your objects should be comparable objects so that they can be sorted.

Are you really sure that the order in the list is different from the resultset order?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question