Sorting a collection within a datatable
-
I'm trying to sort data (by startdate and descendant) in a collection object (CollectionActivities.Sort("StartDate", 0);) and print these data within a datable during run time. Everything is o.k. except the sorting order which is not working. Notice that the same collection(CollectionActivities) is sorting well when It is returned to the caller and bound to a datagrid. My solution require that I use the first way. Any help is highly appreciated. Here is my code: //Enumeration to define the sort orders protected enum enuSortOrder:int { soAscending = 0, soDescending = 1 } private void Page_Load(object sender, System.EventArgs e) { ListScopesWithActivities() } public void ListScopesWithActivities() { ListItemCollectionByScope CollectionScopes = new ListItemCollectionByScope(); ListItemCollectionByScope CollectionGoalDescriptions = new ListItemCollectionByScope(); ListItemCollectionByScope CollectionActivities = new ListItemCollectionByScope(); string colRedImage = "
"; string colGreenImage = "
"; // Define the child controls Table _table = new Table(); TableCell _tableCell; TableRow _tableRow; _table.ID = "InfoTable"; _table.CellPadding = 0; _table.CellSpacing = 0; _table.BorderColor = Color.Tan; _table.BorderWidth = Unit.Pixel(0); _table.BorderStyle = BorderStyle.Solid; _table.GridLines = GridLines.Both; //Get collection of scopes PageDataCollection pdc = Global.EPDataFactory.GetChildren(MogulEPiServer.GetPage(CurrentPage.PageLink.ID).PageLink); if(pdc.Count > 0) { foreach(PageData pd in pdc) { ListActivityItemByScope liScope = new ListActivityItemByScope(); //Get the property values for Scope from PageName string strScope = MogulEPiServer.PageName(pd.PageLink.ID); liScope.Scope = strScope; CollectionScopes.Add(liScope); //Create the row for Scope _tableRow = new TableRow(); _tableCell = new TableCell(); _tableCell.ColumnSpan = 5; _tableCell.Text = "
Område: " + liScope.Scope; _tableRow.Cells.Add(_tableCell); _table.Rows.Add(_tableRow); //Get collection of GoalsDescriptions PageDataCollection pdc2 = Global.EPDataFactory.GetChildren(MogulEPiServer.GetPage(pd.PageLink.ID).PageLink); foreach(PageData pd2 in pdc2) { //Get property values for GoalDescription if(MogulEPiServer.GetPage(pd2.PageLink.ID).Property["GoalDescription"].Value !