London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
protected DataTable GetSortedCategories(string parentCategoryName)
{
DataTable returnValue = new DataTable(parentCategoryName);
returnValue.Columns.Add(new DataColumn("Name", "".GetType()));
returnValue.Columns.Add(new DataColumn("Id", 0.GetType()));
Category cat = Category.Find(parentCategoryName);
IList categories = cat.GetList();
foreach (object obj in categories)
{
Category category = obj as Category;
if (category != null)
{
DataRow dataRow = returnValue.NewRow();
dataRow[0] = category.Name;
dataRow[1] = category.ID;
returnValue.Rows.Add(dataRow);
}
}
returnValue.AcceptChanges();
DataView dv = new DataView(returnValue);
dv.Sort = "Name ASC";
return dv.ToTable();
}
Keep in mind that I haven't done much testing of the code.
best regards
// Stefan
Is there a simple way to retrieve categories from a CategoryList object sorted by name?
By default, if I bind to a CategoryList the individual Category items are returned in Id order.