Adding carriage returns in asp:listbox

  • Thread starter Thread starter BobLaughland
  • Start date Start date
B

BobLaughland

Hi All,

In ASP .NET I have a listbox like this,

<asp:ListBox id="listbox" Height="600" Width="1000" runat="server">
</asp:ListBox>

I want to add items to the listbox (which I am reading out of a
database). Some of those items should appear as one item in the
listbox, but on multiple lines (don't confuse this with multiselect!)

How do I do it?

Let's explain it a bit different, I want to do something like this,

List<string> items = new List<string>();
listbox.DataSource = items;

items.Add("Text to appear on first line \r\n text to appear on
second line");

So in a single selection in the listbox it should have both of the
lines above, and they should be one at the top, and one on the next
line.

But you see that code does not work. I have tried \n, <br\> and many
combinations of the &lt, &gt characters but nothing seems to work.
 
the listbox renders as a select and a select does not support this
feature. you will need a custom control to do this. a scrolling div with
anchors would probably do it.

-- bruce (sqlwork.com)
 
Back
Top