Sorting Text with Numeric Values

3 posts, 0 answers
  1. hugh
    hugh avatar
    2 posts
    Member since:
    Oct 2007

    Posted 30 Dec 2010 Link to this post

    Hi,

    I'm using a RadComboBox which, via a DataSource, is populated with a list of monetary values, i.e. 50, 100, 1,000, 2,000. We need to sort the list from low to high, but because the 'value' of each option is not the same as the text, we need to sort it by text, however, the list is being sorted as strings, rather than as numbers, so anything beginning with a '1' is listed before anything beginning with a '2', i.e. 100, 1,000, 2,000, 50 etc. Is there are way to resolve this so that the text is treated as numeric? We are unable to alter the DataSource.

    Here is my code:

    .ASCX:
    <telerik:RadComboBox runat="server" ID="cbMoney" AutoPostBack="false" width="200px" DataSourceID="MoneyDataSource" DataTextField="Descr" DataValueField="CodeValue" Sort="Ascending"></telerik:RadComboBox>

    .ASCX.VB:
    Protected Sub cbMoney _DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbMoney.DataBound
       
    cbMoney.Items.Sort()
    End Sub

    Thanks in advance,

    Hugh
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 30 Dec 2010 Link to this post

    Hello,


    By default, RadComboBox sorts items by their Text property. I found a help article which shows how to implement custom sorting for RadComboBox based by their Value property. Use the same logic and implement custom sorting for the combo.

    I hope this would shed some light on accomplishing your functionality.
     Implement custom sorting


    -Shinu.
  3. hugh
    hugh avatar
    2 posts
    Member since:
    Oct 2007

    Posted 30 Dec 2010 Link to this post

    Hi,

    Thanks for your response. Unfortunately I have already seen that article, but as per my original message, we are unable to sort by value on this occasion as the values are IDs which correspond to another Db table and therefore do not correspond to the Text or the order we need to list the options in. Is there any other way to sort by Text but treat the text as numbers rather than strings (other than adding leading zeros so all of the numbers are the same length - which is a back-up option)?

    Thanks in advance.

    Hugh
Back to Top