469,949 Members | 1,982 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,949 developers. It's quick & easy.

Listbox item need spaces

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()
Nov 17 '05 #1
6 2740
Is there a question in this somewhere?
I guess it IS a simple question.
Here is the answer to the question " "
Nov 17 '05 #2
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
"Manan" <An******@hotmail.com> wrote in message
news:04****************************@phx.gbl...
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()

Nov 17 '05 #3
I don't know if this works but here is a google search solution. Be careful
of screen wrap.

http://groups.google.com/groups?hl=e...wnlist%2Bspace
"Manan" <An******@hotmail.com> wrote in message
news:04****************************@phx.gbl...
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()

Nov 17 '05 #4
Sorry wrong link.

http://groups.google.com/groups?hl=e...%3D10%26sa%3DN
"Manan" <An******@hotmail.com> wrote in message
news:04****************************@phx.gbl...
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()

Nov 17 '05 #5
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
"vMike" <Mi************@nospam.gewarren.com.delete> wrote in message
news:bh**********@ngspool-d02.news.aol.com...
Sorry wrong link.

http://groups.google.com/groups?hl=e...%3D10%26sa%3DN

"Manan" <An******@hotmail.com> wrote in message
news:04****************************@phx.gbl...
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()


Nov 17 '05 #6
Hi Manan,

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

--
Parker Zhang
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Steve Schroeder | last post: by
4 posts views Thread by Mike Parris | last post: by
1 post views Thread by amber | last post: by
2 posts views Thread by dachrist28 | last post: by
3 posts views Thread by rn5a | last post: by
4 posts views Thread by rn5a | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.