This is a migrated thread and some comments may be shown as answers.

Sorting Text with Numeric Values

2 Answers 165 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
hugh
Top achievements
Rank 1
hugh asked on 30 Dec 2010, 11:26 AM
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 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 Dec 2010, 12:42 PM
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.
0
hugh
Top achievements
Rank 1
answered on 30 Dec 2010, 04:18 PM
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
Tags
ComboBox
Asked by
hugh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
hugh
Top achievements
Rank 1
Share this question
or