Listbox item need spaces

M

Manan

hello All,

I have a simple question..I'm creating a tempString that
contains my values then i'm adding to a ListItemCollection
(). In my tempString i'm adding a spaces between each
values it works fine..when I add to a ListBox the HTML
doesn't render the spaces..Anyhelp is appreciated...

Tanks
Manan

code
-----
tempString = memLastName + Space(5) + memFirstName + Space
(5) + MemDob
tempItem = New ListItem()
tempItem.Text = tempString
tempItem.Value() = MemNbr
tempItemCollection.Add(tempItem)

Next

ListBox1.DataSource = tempItemCollection
ListBox1.DataTextField = "Text"
ListBox1.DataValueField = "Value"
ListBox1.DataBind()
 
G

Guenther Liebowitz

Is there a question in this somewhere?
I guess it IS a simple question.
Here is the answer to the question " "
 
W

William F. Robertson, Jr.

I had to override the RenderContents method of the listbox control, manually
putting out the <option> tags and data.

Before I wrote the Text of the ListItem out, I replaced all ' ' with
'&nbsp;' to get the desired columned effect.

bill
 
S

S. Justin Gengo

Great Link!

I noticed that the code was using the string writer and I wondered why... so
I tried a little experiment and came up with this function:

Private Function Pad(ByVal numberOfSpaces As Int32) As String

Dim Spaces As String

For items As Int32 = 1 To numberOfSpaces

Spaces &= "&nbsp;"

Next

Return Server.HtmlDecode(Spaces)

End Function



Now you can call it and add as many spaces to the front or back of a drop
down list item:

DropDownList1.Items.Add(Pad(5) & "Indented")



Sincerely,


--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
P

Parker Zhang [MSFT]

Hi Manan,

Have you tried Justin's code? If you have any questions, please post back.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top