Solved

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

Posted on 2009-05-20
2
202 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 500 total points
ID: 24436059
Why not use SortedList<>?
0
 
LVL 29

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can I command line build a C# application? 6 40
Winforms -- Capture CTRL+SHIFT+D at the form not working? 3 26
jquery + C#.net radiobuttonlist 3 30
SSIS Start 2 21
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 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