Newline in Radcomboboxitem

2 posts, 0 answers
  1. Javier
    Javier avatar
    3 posts
    Member since:
    Mar 2011

    Posted 05 Jul 2011 Link to this post

    I'm populating information from a webservice into a radcombobox in asp.net.  I would like to force a line break for certain items to clean up the dropdown information.

    No matter what I put in the text field, it always just renders the text and never actually creates a line break.  I looked into creating an itemtemplate for the combobox, but from what I've read, it's not worth the effort when using a webservice.

    Is there an escape character that I could use to force a line break?

    Thanks,
    Javier
  2. Javier
    Javier avatar
    3 posts
    Member since:
    Mar 2011

    Posted 07 Jul 2011 Link to this post

    Here's my resolution.

    The issue wasn't that the line break wasn't occurring, it's that the line break was getting html encoded by the filtering event.  So I had to remove the filtering (contains) from the combobox.  Now the line break appears in the dropdown, but that causes two more issues.

    1) The text <BR> appears in the box after an item is selected
    2) I lose the bolding effect of the filter text.

    To fix both issues I wrote a handler for the OnClientItemsRequested event of the Radcombobox called OnRCBLoad

    function OnRCBLoad(sender, eventArgs) {
        for (i = 0; i < sender.get_items().get_count(); i++) {
            var curText;       
            // Create a regular expression to find the filter text in the list
            var re = new RegExp('(' + sender._filterText + ')', "gi");
            // Grab the text for the current item
            curText = sender.get_items().getItem(i)._element.innerHTML;
            // Bold the filter text in the dropdown
            sender.get_items().getItem(i)._element.innerHTML = curText.replace(re, '<b>$1</b>')                       
            // Remove the linebreak and all subsequent text from the textbox after an item is selected
            sender.get_items().getItem(i)._text = curText.substring(0, curText.indexOf("<BR>"));
        }
      
    }

Back to Top