How to Set Custom Text after Item is Selected?

5 posts, 1 answers
  1. Robert
    Robert avatar
    253 posts
    Member since:
    Aug 2007

    Posted 14 Dec 2012 Link to this post

    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
  2. Answer
    Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 15 Dec 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Robert
    Robert avatar
    253 posts
    Member since:
    Aug 2007

    Posted 15 Dec 2012 Link to this post

    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
  5. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 20 Dec 2012 Link to this post

    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.
  6. Robert
    Robert avatar
    253 posts
    Member since:
    Aug 2007

    Posted 20 Dec 2012 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017