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

Newline in Radcomboboxitem

1 Answer 172 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Javier
Top achievements
Rank 1
Javier asked on 05 Jul 2011, 06:50 PM
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

1 Answer, 1 is accepted

Sort by
0
Javier
Top achievements
Rank 1
answered on 07 Jul 2011, 01:36 PM
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>"));
    }
  
}

Tags
ComboBox
Asked by
Javier
Top achievements
Rank 1
Answers by
Javier
Top achievements
Rank 1
Share this question
or