I have a set of child nodes under a parent node that I sort by a "Sort Order" column in the database based on importance.
However, when I bind, the child nodes insist on sorting alphabetically. How can I force the treeview to accept the list order as is or is there a way to sort after I bind it?
3 Answers, 1 is accepted
Thank you for contacting Telerik Support.
An easy and convenient way of achieving such functionality would be to use the "order by" clause in your sql query. This way the result retrieved by the query will be sorted and then you can use it as a RadTreeView data source. Please refer to this help article for more information.
Also please find in this knowledge base article an approach using server-side code for sorting RadTreeView's Nodes by Text/Value.
Hope that this will be helpful.
That's just it. I'm sorting by a "SortOrder" column on the backend as you suggest.
My collection is listed in this order in the debugger (* indicates values replaced for privacy). "All" being the parent node and the rested as nested nodes one level down. This is how it looks during when I call DataBind.
When I bind the items collection below it insists on sorting the .Text alpha.
RadTreeViewSearchItems.DataTextField = "Text";
RadTreeViewSearchItems.DataFieldID = "RowId";
RadTreeViewSearchItems.DataValueField = "Id";
RadTreeViewSearchItems.DataFieldParentID = "ParentRowId";
RadTreeViewSearchItems.DataSource = items;
The treeview is defined as follows:
<%# DataBinder.Eval(Container, "Text") %>
Please find attached a sample project that demonstrates binding the RadTreeView control to a data set retrieved from a data table. For testing purposes I have commented the default sql query ( without using the order clause by specific column). You can test the application with both queries and notice the differences. When the "ORDER BY LastName" is used all employees are listed in alphabetical order.
SqlDataAdapter adapter =
"SELECT * FROM Employees ORDER BY LastName ASC"
//SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Employees",
DataSet links =
treeView.DataSource = links;