leading space in dropdownlist

T

TJS

I am populating a droplist control from a query.

each line of content in the dropdownlist gets "trimmed" automatically .
how can I force a leading space to a line in a dropdown list ??
 
J

John Timney \(Microsoft MVP\)

The code below has worked for me in the past

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
----------------------------------------------------------------------------
------------------------------------
<blatant plug>
Professional .NET for Java Developers with C#- ISBN: 1-861007-91-4
Professional Windows Forms - ISBN: 1861005547
Professional JSP 2nd Edition - ISBN: 1861004958
Professional JSP - ISBN:
1861003625
Beginning JSP Web Development - ISBN: 1861002092
</blatant plug>
----------------------------------------------------------------------------
------------------------------------

<%@ Page Language="VB" Debug="true" %>
<script language=VB runat=server>

Sub Page_Load(Sender As Object, E As EventArgs)

Dim Padding As String
Dim writer As New System.IO.StringWriter()
Dim DecodedString As String

Padding = "&nbsp;&nbsp;"
Server.HtmlDecode(Padding, writer)
Padding = writer.ToString()

myDropDownList2.Items.Add(Padding & " MVP's")

Padding = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
Server.HtmlDecode(Padding, writer)
Padding = writer.ToString()

myDropDownList2.Items.Add(Padding & " MVP's")

myDropDownList2.Items.Add("MVP's" & Padding & "Do Their best")


End Sub



</script>
<html>
<head><title>Padding DropListBox</title></head>

<body>

<form fred runat="server">

<asp:dropdownlist
id="MyDropDownList2"
runat="server"
/>

</form>

</body>
</html>
 
S

S. Justin Gengo

TJS,

Here's how:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

DropDownList1.Items.Add(Pad(5) & "Item: 1")

End Sub

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


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
S

S. Justin Gengo

Moshitch,

Just for future knowledge &nbsp; gets trimmed too.

You have to encode it to get it to work.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top