Sorting, filtering, or applying any custom rule to an item collection of RadMenu, Radpanelbar, RadTabstrip, RadTreeview or RadCombobox

5 posts, 0 answers
  1. Telerik Admin
    Telerik Admin avatar
    1679 posts
    Member since:
    Oct 2004

    Posted 18 Jun 2007 Link to this post


    RadControls version

    Q1 2007

    .NET version


    Visual Studio version


    programming language

    C#, VB

    browser support

    all browsers supported by RadControls

    This project shows how to sort the child items of data-bound RadMenu, RadPanelbar, RadTabstrip and RadTreeview in the DataBound event. The items of a RadCombobox are sorted on button click. 

    The key idea in this approach is that I store the child items in a collection of the respective type (RadMenuItemCollection, RadPanelItemCollection...). Then I clear the parent item(owner) of its child items collection and add the items again based on some rule. In this project I sort the items by text, but you can easily adjust the approach to sort them by any other property including custom attributes or you can filter the items or just apply any custom rule.
    This is a really flexible method which can suit almost any scenario related to reorganizing a collection of items. The controls do not have to be data-bound but in this case you will have to use the Page Load event. Detailed comments are inserted in the code. I hope you find this project useful and easy to use.
  2. AnanthR
    AnanthR avatar
    1 posts
    Member since:
    Jan 2007

    Posted 21 Jun 2007 Link to this post

    Would'nt it be better to just sort in a PreRender ? Currently the logic would sort for every item (every tab in the tabstrip for example) that is databound?
  3. Peter
    Peter avatar
    6637 posts

    Posted 22 Jun 2007 Link to this post

    Hi Ananth,

    That's a great question! I am glad you raised it. PreRender event will work just fine because it occurs after the DataBound event. However, if you test the approach with Page Load you will find out that it will not sort the items, because Page Load happens before DataBound.

    If the menu is declared inline in the aspx page, the Page Load event is can be used as well as PreRender.

    Kind regards,
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  4. Jeff Willis
    Jeff Willis avatar
    6 posts
    Member since:
    Apr 2006

    Posted 04 Sep 2007 Link to this post

    The only way I could get it to work for a tree view was in the PreRender event, the DataBound event would not do the sort

    It slows things down quite a bit, but it works

  5. Jeff Willis
    Jeff Willis avatar
    6 posts
    Member since:
    Apr 2006

    Posted 05 Sep 2007 Link to this post

    I was wrong - once implemented, all the functionality of the tree view stopped working. The nodechecked event no longer worked correctly and many of the other items stopped working.

    I decided to use a DataVew instead of a DataSet as the source. The DataView is sortable. Works great
Back to Top