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

How to Set Custom Text after Item is Selected?

4 Answers 373 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 14 Dec 2012, 11:23 PM
I have a simple 2-column RadComboBox which I'm using strictly as a dropdown listbox.  It's generally working fine except I'd like to do one more thing with it.  After an item is selected then the short Description text (ex. "228", "3900", "850", etc.) is shown in the RadComboBox after it collapses.

But what I'd like to do is display the related text as a suffix.  So, for example, if the first item is selected then rather than just display "228", instead I'd like to display "228 (601-10101 / 4000)".

I tried doing this by setting the RadComboBox's Text property but this failed to achieve it.  I then also tried setting the EmptyMessage property but that didn't work either.

Is there a way I can do it?

Robert

4 Answers, 1 is accepted

Sort by
0
Accepted
Kevin
Top achievements
Rank 2
answered on 15 Dec 2012, 02:25 PM
Hello Robert,

The easy answer would be to create another column in your query that concatenates the two and then set that as the DataTextField. That way when you select the item, that is the text it will show in the RadComboBox.

I hope that helps.
0
Robert
Top achievements
Rank 1
answered on 16 Dec 2012, 02:20 AM
Kevin,

Yes, I realize that is a possibility ... if such a calculated field did not appear when I opened up the RadComboBox.

But I wonder if there's a simpler way?

Robert
0
Nencho
Telerik team
answered on 20 Dec 2012, 07:45 AM
Hello Rober,

I can suggest you to store the "Contact/Level" column data for each RadComboBoxItem like an Attribute for the corresponding item. The implementation of this approach is used in our online demo in the RadComboBoxProduct_ItemsRequested event handler. In addition, on the ClientSelectedIndexChanged you could access the previously stored attribute and set the text of the RadComboBox in the following manner:

function OnClientSelectedIndexChanged(sender, args) {
           var item = args.get_item();
           if (item != null) {
               sender.set_text(item.get_text() + " + " +
               item.get_attributes().getAttribute("ContactLevel"));
           }
       }



All the best,
Nencho
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Robert
Top achievements
Rank 1
answered on 20 Dec 2012, 11:08 PM
Thanks, Nencho.  However, I prefer Kevin's approach.  It keeps everything in server-side code and works well.

May I share something else with you, in the realm of the "big picture"?

While I think you guys at Telerik are very talented, very knowledgeable, one thing I don't believe you fully understand is that most corporate-type developers, like myself, are simply nowhere near as adept as you guys at Javascript programming.  So, while I can usually get the Javascript I require working ... eventually, it's most certainly not my forté.  Furthermore, I don't know of any Computer Science Professor who would agree that writing an application in 3 languages is as solid, dependable, reliable, reusable as writing it in 1 or 2.

With my ASP.NET / SQL Server work, I am forced to use at least 2 languages: C# and T-SQL.  Writing AND MAINTAINING Javascript code was something I initially wanted to avoid at all cost but then had to add to effect some of the user functionality I wanted to provide.  But for the large business app I'm writing, which will probably be used by my corporate client for the next 10 - 20 years, it may be a nightmare if one day the Javascript has to be tweaked because of some change made by Microsoft or Telerik or the browser manufacturer.

In summary, I'm not complaining per say but just stating that for many of your customers, if a server-side solution can be found, it's almost always preferable to a client-side solution.
Tags
ComboBox
Asked by
Robert
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Robert
Top achievements
Rank 1
Nencho
Telerik team
Share this question
or