By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,725 Members | 1,094 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,725 IT Pros & Developers. It's quick & easy.

How to add " " to list item text

P: n/a
I am try to set the text of the drop down list item as

ListItem li = new ListItem();
li.Text = " "+"MyValue";

myDropDown.Items.Add("li);

The intent is to add a spacing in front of the text. Its not doing what I am
trying to do. The text shows up as "&ampMyValue"

How can this be accomplished?
Nov 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Thanks Justin,
I tried that. It truncates the blank spaces at the start. In regular ASP
apps I was able to do..

<option>&nbsp;&nbsp;MyValue

I am trying to do the same thing with DropdownList control
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:um**************@tk2msftngp13.phx.gbl...
Naveen,

Drop down lists don't use the same encoding as regular html on the page.

Just add a regular " " space.

Sincerely,
--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Naveen K Kohli" <na*********@hotmail.com> wrote in message
news:ON**************@TK2MSFTNGP12.phx.gbl...
I am try to set the text of the drop down list item as

ListItem li = new ListItem();
li.Text = "&nbsp;"+"MyValue";

myDropDown.Items.Add("li);

The intent is to add a spacing in front of the text. Its not doing what
I am
trying to do. The text shows up as "&ampMyValue"

How can this be accomplished?


Nov 17 '05 #2

P: n/a
What I think the issue is is that you are using the "+" to
add both strings..i think you must use the & char.

Well in VB.Net in C# your right on the money I think..you
use the "+"..but you didn't specify any language

ListItem li = new ListItem();
li.Text = "&nbsp;" & "MyValue";

myDropDown.Items.Add("li");
-----Original Message-----
Thanks Justin,
I tried that. It truncates the blank spaces at the start. In regular ASPapps I was able to do..

<option> MyValue

I am trying to do the same thing with DropdownList control
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in messagenews:um**************@tk2msftngp13.phx.gbl...
Naveen,

Drop down lists don't use the same encoding as regular html on the page.
Just add a regular " " space.

Sincerely,
--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Naveen K Kohli" <na*********@hotmail.com> wrote in message news:ON**************@TK2MSFTNGP12.phx.gbl...
> I am try to set the text of the drop down list item as
>
> ListItem li = new ListItem();
> li.Text = " "+"MyValue";
>
> myDropDown.Items.Add("li);
>
> The intent is to add a spacing in front of the text.
Its not doing whatI
am
> trying to do. The text shows up as "&MyValue"
>
> How can this be accomplished?
>
>


.

Nov 17 '05 #3

P: n/a
I think choice of language was clear. I don't think that VB uses ";" at the
end of statement. Thats not the point.
ListItem truncates the leading spaces. And if you have any HTML decoded
string, it will encode it and display as "&ampndp;". The solution to this
issue can be found at floowing link.,

http://www.netomatix.com/IndentDropdownList.aspx

Naveen

"Tyrone" <t_*******@hotmail.com> wrote in message
news:08****************************@phx.gbl...
What I think the issue is is that you are using the "+" to
add both strings..i think you must use the & char.

Well in VB.Net in C# your right on the money I think..you
use the "+"..but you didn't specify any language

ListItem li = new ListItem();
li.Text = "&nbsp;" & "MyValue";

myDropDown.Items.Add("li");
-----Original Message-----
Thanks Justin,
I tried that. It truncates the blank spaces at the start.

In regular ASP
apps I was able to do..

<option> MyValue

I am trying to do the same thing with DropdownList control
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in

message
news:um**************@tk2msftngp13.phx.gbl...
Naveen,

Drop down lists don't use the same encoding as regular html on the page.
Just add a regular " " space.

Sincerely,
--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Naveen K Kohli" <na*********@hotmail.com> wrote in message news:ON**************@TK2MSFTNGP12.phx.gbl...
> I am try to set the text of the drop down list item as
>
> ListItem li = new ListItem();
> li.Text = " "+"MyValue";
>
> myDropDown.Items.Add("li);
>
> The intent is to add a spacing in front of the text.

Its not doing what
I
am
> trying to do. The text shows up as "&MyValue"
>
> How can this be accomplished?
>
>

.

Nov 17 '05 #4

P: n/a
The code below should help you out.
--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_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
</shameless_author_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;&nb sp;"
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>

Nov 17 '05 #5

P: n/a
John,
I did try this before posting the code. Nothing seemed to work. &nbsp; did
not show up as spaces.

Thanks.

"John Timney (Microsoft MVP)" <ti*****@despammed.com> wrote in message
news:eu**************@TK2MSFTNGP10.phx.gbl...
The code below should help you out.
--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_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
</shameless_author_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;&nb sp;"
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>

Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.