to sort a column from an entity

Posts   
 
    
Posts: 1
Joined: 27-Sep-2005
# Posted on: 27-Sep-2005 16:40:07   

Hello, Can u plz help me to solve this . with out using Collection i want sorting of a coulmn ,i am sending from the table1 ,column1.

this column1 is the Primary key of another table ,Table2 .here i am filling a DropdownList1 with values of Column1 .and i want them in a sorted order can u plz help me /// foreach(deptEntity airety in deptCollection) { empEntity sta=new empEntity(airety.empID); using (DataAccessAdapter adapterSta=new DataAccessAdapter()) { adapterSta.FetchEntity(sta);

} ListItem itemDSta = new ListItem(); Guid Depemp=sta.empID; itemDSta.Value = airety.empID.ToString(); itemDSta.Text = airety.emp.DisplayName;
dropdownlist1.Items.Add(itemDSta); }

i am not using any collection .i am getting the Column1 data from the Table2.and displaying it into the dropdownlist. with this i am unable to sort the values , i have tried with the following code of line also "dropdownlist1.Items.Insert(i, new ListItem(airety.emp.DisplayName,airety.emp.ToString()));"

thankyou

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 28-Sep-2005 03:15:59   

So each of your deptartment entities only have one employee and you want to sort on that employees display name. You could set this up by including the DisplayName as a related field for deptartment that is read-only and then call

deptCollection.Sort((int)DeptartmentFieldIndex.EmployeeDisplayName, ListSortDirection.Ascending);

before your foreach.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-Sep-2005 16:48:06   

I'm not sure what you are trying to do, but as your code suggests, it looks like you're having one employee tied to each department.

And first you fetch all the departments in one collection, and then you loop on this collection to fetch each employee of tied to each department using the "empID" FK

Then you insert each employee's name and id in a dropdown list.

And I guess you want this list sorted by employee name or employee id.

If so...then you have many options.

1- To use an Entity Collection of Employees filled with every employee you fetch, then use the sort function of this Collection, then u might want to bind it to the dropdown list

2- If you want the items sorted by empID: 2.1- You might use the departments' collection Sort function to sort on the empID before fetching the employees one by one. 2.2- You might use the sort clause in the FetchEntityCollection function to fetch the departments sorted by empID

3- If you want to sort by empName then use bclubb suggestion to include EmployeeName as a related field of the departments, thus having all the needed data in just one fetch, better than having as many fetches as the number of departments that you have.

3.1- You might use the departments' collection Sort function to sort on the empName 3.2- You might also use the sort clause in the FetchEntityCollection function to fetch the departments sorted by empName