Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
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.