Solved

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

Posted on 2009-05-20
2
203 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

737 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