Click here to Skip to main content
15,903,388 members
Please Sign up or sign in to vote.
4.33/5 (3 votes)
See more:
i fill sorted list from ordered datatable but after fill sorted list my order changing

C#
for (int i = 0; i < d.Rows.Count; i++)
           {
                 int EmpID = Convert.ToInt32(d.Rows[i]["Fd_Emp"].ToString().Trim());
               string type=d.Rows[i]["Fd_Type"].ToString().Trim();
               emp.Add(EmpID, type);

           }



my datatable order is 31e,32e,33e,7i

my sortedlist order become 7i,31e,32e,33e

how to keep my datatable order in my sorted list
Posted
Comments
ZurdoDev 13-Apr-12 12:18pm    
What is emp?
nagiub2007 13-Apr-12 12:27pm    
int record from database i concatenate with type (another record) but i want order

1 solution

The reason is in the SortedList, the key is added as an integer. So, the order will be 7, 31, 32, 33. Whereas, in the DataTable the value is text, hence, the order is 31e, 32e, 33e, 7i.
To get the same sort as in data table, add the key as text
i.e.
C#
emp.Add(key, type);

where key is 31e, 32e, 33e, 7i
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900