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

Thread is closed for posting
5 posts, 0 answers
  1. 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD avatar
    1572 posts
    Member since:
    Oct 2004

    Posted 18 Jun 2007 Link to this post

    Requirements

    RadControls version

    Q1 2007

    .NET version

    2.0    

    Visual Studio version

    2005

    programming language

    C#, VB

    browser support

    all browsers supported by RadControls


     
    PROJECT DESCRIPTION
    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. F7B77A5D-90A1-49A9-A108-A21A37C739A4
    F7B77A5D-90A1-49A9-A108-A21A37C739A4 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. 8AECA7A5-3E26-4708-AD62-47AA92940523
    8AECA7A5-3E26-4708-AD62-47AA92940523 avatar
    6637 posts
    Member since:
    Sep 2012

    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,
    Peter
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  4. C502871A-F083-4497-AC06-515F0130EE5A
    C502871A-F083-4497-AC06-515F0130EE5A 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. C502871A-F083-4497-AC06-515F0130EE5A
    C502871A-F083-4497-AC06-515F0130EE5A 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

This Code Library is part of the product documentation and subject to the respective product license agreement.