Solved

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

Posted on 2009-05-20
2
198 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 74

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now